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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image uploding via file field

Status
Not open for further replies.

photores

Programmer
Sep 12, 2000
13
0
0
RU
Hi!
I try upload image to server via form. I take working code, make some modifications, and try use it on my desktop (Win98, Apache for Win)>:-( You can see it here:
1.jpg

Code sample is below:
-----------------------------------------------------
my $im_file = $co->param("img_$no");
@pathName = split(/\\/,$im_file);
$newFile = pop(@pathName);
($name,$ext) = split('\.',$newFile);
$newFile = "$no.$ext";
if($im_file) {
open(OUTFILE,">$tmp_dir/images/$newFile")||die "Can not open $newFile. $!";
while($bytesread=read($im_file,$buffer,1024)) {
print OUTFILE $buffer;
}
close(OUTFILE);
}
---------------------------------------------------
I seem, problem is in server configuration. Can any help me?
 
That looks to me like what happens to images when you upload them as ascii and not binary, which I have done before by mistake. What to actually do about it I don't know, but hope that may provide a clue if it doesn't throw you totally off track...

Matt.
 
hi photores,
can you give more symptoms? What errors are you getting in the browser? or What does the Apache error_log say? Or, does file get created, but, it is empty? Or,.....??????

The code you are using looks very familiar ;-) It should work for an image, just fine.




keep the rudder amid ship and beware the odd typo
 
After you open OUTFILE, before you print $buffer, use:

binmode(OUTFILE);

Otherwise it assumes ASCII mode. You need to do this for images, executables, or anything else which is not plain text.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Hi!
Thank for your answers. I too think, this is result of loading image in ascii. The string: binmode OUTFILE; does not help. I know, that the apache change encoding for the transmitted information and it can give such outcome. It is possible switch off it for definite types of files or to switch off absolutely. May be who knows code for configuration file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top