sub upload_file
{
my $bytes_read=0;
my $size='';
my $buff='';
my $start_time;
my $time_took;
my $filepath='';
my $filename='';
my $write_file='';
$g_upload_path = "../artpics/";
$g_overwrite = 1;
$filepath=$fields{"filename1"};
print "Filepath = $filepath <br>";
if ($filepath =~ /([^\/\\]+)$/)
{
$filename="$1";
}
else
{
$filename="$filepath";
}
# if there's any space in the filename, get rid of them
$filename =~ s/\s+//g;
$write_file="$g_upload_path" ."$filename";
print "Filename=$filename<br>\n";
print "Writefile= $write_file<br>\n";
if ($g_overwrite == 0)
{
if (-e $write_file)
{
print("File $filename exists, will not overwrite!");
return;
}
}
if (!open(WFD,">$write_file"))
{
print "Write Filename = ",$write_file;
print "Error opening file for writing. It's a permission problem. Make sure your web server has write permission to the upload directory";
return;
}
$start_time=time();
$size = 0;
# no strict 'refs';
# binmode ($filepath);
while ($bytes_read=read($filepath,$buff,1024))
{
$size += $bytes_read;
binmode WFD;
print WFD $buff;
print "OK<br>";
}
print "size= ", $size,"<br>\n";
close(WFD);
if ((stat $write_file)[7] <= 0)
{
unlink($write_file);
print "Could not upload file: $filename";
return;
}
else
{
$time_took=time()-$start_time;
}
}
The results are:
Filepath = C:\2001.jpg
Filename=2001.jpg
Writefile= ../artpics/2001.jpg
size= 0
File 2001.jpg of size 0 bytes is uploaded successfully!
I have tried variations of the commented out lines for binmode and no strict but no luck. I get a file created in the right place with no data in it.
Not having handled multipart form data, this change pretty much broke the rest of my perl script, but I will figure out how to put it back together.
I'm an old school c programmer that has been out of technology for awhile. I'm not html/cgi literate yet. I've been begging and learning as I go. What is a good resource to find on using forms with cgi/perl.
As an old school programmer, I want to know what is under the covers. I'm not looking for a lot of routines that others have written.
I'm an old school c programmer that has been out of technology for awhile. I'm not html/cgi literate yet. I've been begging and learning as I go. What is a good resource to find on using forms with cgi/perl.
Hmm, not really sure. I tend to either use the CPAN modules or just parse the data out in the code. I also frequent perldoc.com a lot to look up perl functions and man pages.
BTW, the reason I suspected multipart/form-data was that I have been burned by it so many times - eventually I do learn! Glad it's working now. :)
Scott