Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload File, File Size=0?

Status
Not open for further replies.

CherylD

Programmer
Joined
May 1, 2001
Messages
107
Location
CA
I am uploading a file via the web to our server, only the file never actually goes. It's file size is always zero. These are image files.

Here is the code I am using:
open IMAGE, ">$image";
binmode(IMAGE);
print IMAGE $buffer;

What should I be looking for?

Cheryl
 
How are you getting the contents of the uploaded file into $buffer?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I'm not sure what you mean?
 
You are printing the variable $buffer to the image file you opened, so it should contain the image file you are trying to write. If it doesn't, then that's why the file size is 0, because the variable is null. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I see, okay I changed $buffer to $file thinking that it would image that way, the file size changes to an actual amount, only the file now displays as a text file containg the path to the file that should have been uploaded. So $file does not contain the image that I want, it contains the path, how/what contains the image that I want to upload?

Cheryl
 
You'll need to open the file whose name is in $file and read it into $buffer (with binmode), then write it out as your are doing. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You are so very helpful, but I'm still unsure of how to do that. Everyway I try doesn't work. Maybe some sample code?

Thanks.

Cheryl
 
I can't gaurantee this will work, but give this a try:
Code:
open FILE, "$file";      
binmode(FILE);  
$buffer = <FILE>;
close FILE;
open IMAGE, &quot;>$image&quot;;      
binmode(IMAGE);  
print IMAGE $buffer;
close IMAGE;


Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Make sure you have the following checklist

[I assume that you are using CGI.pm module]

1. Make sure you are creating a File handle for the
file you are uploading

<code>
$File_Handle = $query->param('myfile');
</code>

# File handle is the value of your File Input
# object as in <input type=file name=myfile >

2. Code to read contents of uploaded file part by part


<code>

$entire_file=&quot;&quot;;
while (read($File_Handle,$Buffer,1024))
{
$entire_file.=$Buffer
}

print OUTPUTFILE $entire_file;

</code>

where OUTPUTFILE is the Filehandle to the file you want
to write to



HTH

CM
 
there are a couple of faqs on this with several examples.


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top