sulfericacid
Programmer
The script below was over 200 lines earlier. I posted everything in the sub into each if originally and thought it was too messy and decided to try and shorten the script. My idea was to make all the real processing instructions or whatever you want to call it inside the subroutine and just call it for each <b>if</b>/filefield.
I used $num++ originally instead of $field which worked but that had one problem. If you filled in field3 and NOT field2 or field1 it would error out because the $field$num wouldn't match up.
My next idea was to use static numbers or the fields (as you see below). I use $field = 1 for param('upload1'), $field = 2 for param('upload2') and so on. This way SHOULD work because it doesn't matter which fields they have data in, they all have their own static numbers to work on. BUT SOMETHING DOESN'T WORK! It used to upload files when using $num but now it doesn't. It tries to upload and refreshes the screen but nothing happens. Can someone figure out why?
if ( param('upload1') ) {
my $field = "1";
&dirty_work;
}
if ( param('upload2') ) {
my $field = "2";
&dirty_work;
}
if ( param('upload3') ) {
my $field = "3";
&dirty_work;
}
if ( param('upload4') ) {
my $field = "4";
&dirty_work;
}
sub dirty_work {
# take form data
my $remotefile = param("upload$field"
# 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 = "
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 "<br>";
print "<b>File:</b><br>";
print
qq(File was uploaded to <a href="$url\/$filename">$url\/$filename</a><br>);
print
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">
print "<br>";
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
I used $num++ originally instead of $field which worked but that had one problem. If you filled in field3 and NOT field2 or field1 it would error out because the $field$num wouldn't match up.
My next idea was to use static numbers or the fields (as you see below). I use $field = 1 for param('upload1'), $field = 2 for param('upload2') and so on. This way SHOULD work because it doesn't matter which fields they have data in, they all have their own static numbers to work on. BUT SOMETHING DOESN'T WORK! It used to upload files when using $num but now it doesn't. It tries to upload and refreshes the screen but nothing happens. Can someone figure out why?
if ( param('upload1') ) {
my $field = "1";
&dirty_work;
}
if ( param('upload2') ) {
my $field = "2";
&dirty_work;
}
if ( param('upload3') ) {
my $field = "3";
&dirty_work;
}
if ( param('upload4') ) {
my $field = "4";
&dirty_work;
}
sub dirty_work {
# take form data
my $remotefile = param("upload$field"
# 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 = "
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 "<br>";
print "<b>File:</b><br>";
qq(File was uploaded to <a href="$url\/$filename">$url\/$filename</a><br>);
qq(<p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\">
print "<br>";
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid