#!/usr/bin/perl -w
open( STDERR, ">>/home/sulfericacid/public_html/test/error.log" )
or die "Cannot open error log, weird...an error opening an error log: $!";
use warnings;
use CGI qw/:standard/;
use POSIX;
my $mode = 0755;
print header, start_html('upload form');
print "Upload formats allowed: jpg, gif, bmp.
";
print start_form(
-method => 'post',
-enctype => 'multipart/form-data',
-action=> ''
),
table(
Tr(
td("File: "),
td(
filefield(
-name => 'upload',
-size => 50,
-maxlength => 80
),
),
),
Tr(
td("File: "),
td(
filefield(
-name => 'upload2',
-size => 50,
-maxlength => 80
),
),
),
Tr(
td("File: "),
td(
filefield(
-name => 'upload3',
-size => 50,
-maxlength => 80
),
),
),
Tr(
td("File: "),
td(
filefield(
-name => 'upload4',
-size => 50,
-maxlength => 80
),
),
),
Tr( td(), td( submit( 'button', 'submit' ), ) )
),
end_form(), hr;
print "By clicking Submit you are agreeing to any legal discreptancies involved with the images you upload";
print " leaving the designer of this script or the webhost itself not responsible. You are agreeing these";
print " pictures are not copyright material, do not contain viruses and does not promote sexual or violence";
print " activities. It is a legal signature of awknowledgement once you click the Submit button.
";
if ( param('upload') ) {
# take form data
my $remotefile = param('upload');
# make new variable to prevent overwriting of form data
my $filename = $remotefile;
# remove all directories in the file name path
$filename =~ s/^.*[\\\/]//;
# full file path to upload directory (must include filename)
my $localfile = "/home/sulfericacid/public_html/amy/files/$filename";
# full url to upload directory (cannot include filename or an end slash /)
my $url = "http://sulfericacid.perlmonk.org/amy/files";
my $type = uploadInfo($remotefile)->{'Content-Type'};
unless ( $type eq 'image/pjpeg' || $type eq 'image/gif' || $type eq 'image/bmp') {
print "Wrong! This is not a supported file type.";
exit;
}
# print "type: $type
";
# open a new file and transfer bit by bit from what's in the buffer
open( SAVED, ">>$localfile" ); # || die $!;
while ( $bytesread = read( $remotefile, $buffer, 1024 ) ) {
print SAVED $buffer;
}
close SAVED;
chmod $mode, "$localfile"; # or die "can't chmod: $!";
# required since module was not preinstalled on server
use lib "/home/sulfericacid/public_html/lib/";
use Image::Info qw(image_info dim);
# assigning info to a filename (better be an image)
my $info =
image_info("$localfile");
# if for any reason we can't open the file, this error trap should pick it up
if ( my $error = $info->{error} ) {
#die "Can't parse image info: $error\n";
}
# unommit next line if you want to use/post the image's color
#my $color = $info->{color_type};
# declaring the width and heighth of your image
my ( $w, $h ) = dim($info);
print "
";
print "File 1:
";
print
qq(File was uploaded to $url\/$filename
);
print
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">);
print "
";
}
if ( param('upload2') ) {
# take form data
my $remotefile = param('upload2');
# make new variable to prevent overwriting of form data
my $filename = $remotefile;
# remove all directories in the file name path
$filename =~ s/^.*[\\\/]//;
# full file path to upload directory (must include filename)
my $localfile = "/home/sulfericacid/public_html/amy/files/$filename";
# full url to upload directory (cannot include filename or an end slash /)
my $url = "http://sulfericacid.perlmonk.org/amy/files";
my $type = uploadInfo($remotefile)->{'Content-Type'};
unless ( $type eq 'image/pjpeg' || $type eq 'image/gif' || $type eq 'image/bmp') {
print "Wrong! This is not a supported file type.";
exit;
}
# open a new file and transfer bit by bit from what's in the buffer
open( SAVED, ">>$localfile" ); # || die $!;
while ( $bytesread = read( $remotefile, $buffer, 1024 ) ) {
print SAVED $buffer;
}
close SAVED;
chmod $mode, "$localfile"; # or die "can't chmod: $!";
# required since module was not preinstalled on server
use lib "/home/sulfericacid/public_html/lib/";
use Image::Info qw(image_info dim);
# assigning info to a filename (better be an image)
my $info =
image_info("$localfile");
# if for any reason we can't open the file, this error trap should pick it up
if ( my $error = $info->{error} ) {
#die "Can't parse image info: $error\n";
}
# unommit next line if you want to use/post the image's color
#my $color = $info->{color_type};
# declaring the width and heighth of your image
my ( $w, $h ) = dim($info);
print "
";
print "File 2:
";
print
qq(File was uploaded to $url\/$filename
);
print
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">);
print "
";
}
if ( param('upload3') ) {
# take form data
my $remotefile = param('upload3');
# make new variable to prevent overwriting of form data
my $filename = $remotefile;
# remove all directories in the file name path
$filename =~ s/^.*[\\\/]//;
# full file path to upload directory (must include filename)
my $localfile = "/home/sulfericacid/public_html/amy/files/$filename";
# full url to upload directory (cannot include filename or an end slash /)
my $url = "http://sulfericacid.perlmonk.org/amy/files";
my $type = uploadInfo($remotefile)->{'Content-Type'};
unless ( $type eq 'image/pjpeg' || $type eq 'image/gif' || $type eq 'image/bmp') {
print "Wrong! This is not a supported file type.";
exit;
}
# print "type: $type
";
# open a new file and transfer bit by bit from what's in the buffer
open( SAVED, ">>$localfile" ); # || die $!;
while ( $bytesread = read( $remotefile, $buffer, 1024 ) ) {
print SAVED $buffer;
}
close SAVED;
chmod $mode, "$localfile"; # or die "can't chmod: $!";
# required since module was not preinstalled on server
use lib "/home/sulfericacid/public_html/lib/";
use Image::Info qw(image_info dim);
# assigning info to a filename (better be an image)
my $info =
image_info("$localfile");
# if for any reason we can't open the file, this error trap should pick it up
if ( my $error = $info->{error} ) {
#die "Can't parse image info: $error\n";
}
# unommit next line if you want to use/post the image's color
#my $color = $info->{color_type};
# declaring the width and heighth of your image
my ( $w, $h ) = dim($info);
print "
";
print "File 3:
";
print
qq(File was uploaded to $url\/$filename
);
print
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">);
print "
";
}
if ( param('upload4') ) {
# take form data
my $remotefile = param('upload4');
# make new variable to prevent overwriting of form data
my $filename = $remotefile;
# remove all directories in the file name path
$filename =~ s/^.*[\\\/]//;
# full file path to upload directory (must include filename)
my $localfile = "/home/sulfericacid/public_html/amy/files/$filename";
# full url to upload directory (cannot include filename or an end slash /)
my $url = "http://sulfericacid.perlmonk.org/amy/files";
my $type = uploadInfo($remotefile)->{'Content-Type'};
unless ( $type eq 'image/pjpeg' || $type eq 'image/gif' || $type eq 'image/bmp') {
print "Wrong! This is not a supported file type.";
exit;
}
# print "type: $type
";
# open a new file and transfer bit by bit from what's in the buffer
open( SAVED, ">>$localfile" ); # || die $!;
while ( $bytesread = read( $remotefile, $buffer, 1024 ) ) {
print SAVED $buffer;
}
close SAVED;
chmod $mode, "$localfile"; # or die "can't chmod: $!";
# required since module was not preinstalled on server
use lib "/home/sulfericacid/public_html/lib/";
use Image::Info qw(image_info dim);
# assigning info to a filename (better be an image)
my $info =
image_info("$localfile");
# if for any reason we can't open the file, this error trap should pick it up
if ( my $error = $info->{error} ) {
#die "Can't parse image info: $error\n";
}
# unommit next line if you want to use/post the image's color
#my $color = $info->{color_type};
# declaring the width and heighth of your image
my ( $w, $h ) = dim($info);
print "
";
print "File 4:
";
print
qq(File was uploaded to $url\/$filename
);
print
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">);
print "
";
}