Gossamer Forum
Home : General : Perl Programming :

file uploads

Quote Reply
file uploads
Hi:

Non Image
Can anyone show me a snippet of code to do a file upload in perl

Image
Also how to upload and modify the width and height of an image that is uploaded.
Quote Reply
Re: [akastarlight] file uploads In reply to
Although links has some features that do this automatically (if that is what you use) the basic syntax is this:

For your html page:

Code:

<form action="path to your perl file" method="post">

<input type=file name=uploadfile size=30>
<input type=submit>
</form>


For the perl file:
Code:


my $file = $IN->param('uploadfile');
open (FILE, ">..path/to/save") or die "error";
my ($data, $length, $chunk);
while ($chunk = read ($file, $data, 1024)) {
print FILE $data;
$length += $chunk;
if ($length > 51200) {
print "file too big message.";
exit;
}
}
close (FILE);


Hope this helps,

- Jonathan
Quote Reply
Re: [jdgamble] file uploads In reply to
The maximum POST size can also be specified. That is usually a better way to handle it. See CGI in perldoc.

There are a bunch of image related modules that will do all sorts of things with images. Which you want depends on what you have installed and what you need. Look on search.cpan.org.