Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Upload a file from a web form

by CodeJunkie (Monk)
on Jul 10, 2003 at 09:26 UTC ( #272921=note: print w/replies, xml ) Need Help??


in reply to Upload a file from a web form

This works for me, hope its some help to you.

open (OUTPUT,">$outfile") || die "Cannot open image file: $!"; binmode(OUTPUT); my $buffer; while (my $bytesread = read($filename_thumbnail, $buffer, 4096)) { my $length += $bytesread; print OUTPUT $buffer || die "Cannot write the image to file: $!"; } close OUTPUT || die "Cannot close image file: $!"; my $koko = int(($length+512)/1024); my $maxsize="1024"; if($koko > $maxsize && $maxsize > 0) { unlink "$outfile"; print "File size is limited to ". $maxsize ."KB<br>$koko"; }

Then the form should look like this

<form name="additem" method="post" action="$ENV{'SCRIPT_NAME'} enctype +="multipart/form-data"> <input type="file" name="outfile" size="10" class="submit"> <input type="submit"> </form>

I kinda missed out some usual CGI and perl bits there, but I hope that's some help to you.

Cheers,
Tom

Replies are listed 'Best First'.
Re: Re: Upload a file from a web form
by CodeJunkie (Monk) on Jul 10, 2003 at 09:29 UTC

    Just looking over the responses again, maybe your all important missing code is the

    binmode(OUTPUT);

    Just a thought... let me know if it helps any

      Wish it did help. But no, thanks all the same.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://272921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2020-05-31 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (177 votes). Check out past polls.

    Notices?