DB not saving everything

S

spyderscripts

I have an html form to upload files with. The uploads are sent to
their own directory, which works. But..the database isn't saving
everything. It's only saving the last file to database (if you
uploaded 4 files, all 4 files are uploaded but the database only shows
#4). Could this be because I'm using localtime() as the key? I was
told that even though it's one form, the time each of them are
actually uploaded will be different.

Thanks for your help.



if ( param('upload1') ) {

my $num = 1;

&dirty_work($num);

}

if ( param('upload2') ) {

my $num = 2;

&dirty_work($num);
}

if ( param('upload3') ) {

my $num = 3;

&dirty_work($num);
}

if ( param('upload4') ) {

my $num = 4;
&dirty_work($num);
}







sub dirty_work {
my $num = shift;
# take form data
my $remotefile = param("upload$num");
# make new variable to prevent overwriting of form data
my $filename = $remotefile;

my $title = param("title$num");
my $desc = param("desc$num");

# 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/playground/upload/files/$filename";

# full url to upload directory (cannot include filename or an end
slash /)
my $url = "http://sulfericacid.perlmonk.org/playground/upload/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);

my $combo = join("::", $filename, $title, $desc, $w, $h);
$upload{localtime()} = "$combo";



print "<br>";
print "<b>File:</b><br>";
print
qq(File was uploaded to <a
href="$url\/$filename">$url\/$filename</a><br>);
print
qq(&lt;p style =\"background:url\($url\/$filename\)\;width:$w\;height:$h\;\"&gt;);
print "<br>";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top