Click here to get back home

file upload

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
file upload kalikoi 01-05-2006
| |--> Re: file upload Gunnar Hjalmars...01-05-2006
|   ---> Re: file upload Gunnar Hjalmars...01-05-2006
|     | ---> Re: file upload Gunnar Hjalmars...01-05-2006
|     |     |--> Re: file upload Gunnar Hjalmars...01-06-2006
|     |     `--> Re: file upload Martin Vorlaend...01-06-2006
|     `--> Re: file upload Gunnar Hjalmars...01-05-2006
`--> Re: file upload Gunnar Hjalmars...01-05-2006
Posted by kalikoi on January 5, 2006, 7:00 am
Please log in for more thread options


Hi


I'm using the following code for PDF file upload via perl


The code is working.


but the file size is zero bytes


any suggestions


#!/usr/local/bin/perl -w


####### Load Needed Perl Modules ######
use strict;
# Make HTML/FORMS/UPLOADING easy to deal with
use CGI;
# Report errors in the browser
use CGI::Carp 'fatalsToBrowser';
# Limit file size
$CGI::POST_MAX=500000; # max 100K posts
####### End Perl Module Load #######


# Create new CGI object
my $q = new CGI;


if ( $q->param() ) {


# read filehandle from param and set to binary mode
my $filehandle = $q->param('proof_file');
binmode($filehandle);


# Strip off WINDOZE path crap
$_=$filehandle;
s/.*\//;
my $filename=$_;


# open file for output - change this to suit your needs!!!
open(OUT,">upload/$filename") || die $!;
binmode(OUT);


# process $filehandle
{
my $buffer;
while ( read($filehandle,$buffer,500000) ) {
print OUT $buffer;
}
}


# close output file
close(OUT);


# show success
print $q->header,
$q->start_html,
$q->p('File uploaded: $filename'),
$q->end_html;
exit(0);



}


Thanks & Regards

kalyan kamesh



Posted by Paul Lalli on January 5, 2006, 10:56 am
Please log in for more thread options


kalikoi@gmail.com wrote:
> I'm using the following code for PDF file upload via perl
>
> The code is working.
> but the file size is zero bytes

You have an odd definition of "working".

> # Strip off WINDOZE path crap
> $_=$filehandle;
> s/.*\//;
> my $filename=$_;

Yuck. perldoc File::Basename

> # process $filehandle
> {
> my $buffer;
> while ( read($filehandle,$buffer,500000) ) {
> print OUT $buffer;
> }
> }

How was the parameter which lead to $filehandle generated? In your
form, did you remember to add the enctype="multipart/form-data"
attribute to the form tag? Are you sure the input was type="filefield"
rather than type="text"? Show us the whole process, not just one side
of it.

Paul Lalli



Posted by Matt Garrish on January 5, 2006, 2:05 pm
Please log in for more thread options



> kalikoi@gmail.com wrote:
>> I'm using the following code for PDF file upload via perl
>>
>> The code is working.
>> but the file size is zero bytes
>
>
> How was the parameter which lead to $filehandle generated? In your
> form, did you remember to add the enctype="multipart/form-data"
> attribute to the form tag? Are you sure the input was type="filefield"

I suspect you meant: type="file"

Matt




Posted by Paul Lalli on January 5, 2006, 11:24 am
Please log in for more thread options


Matt Garrish wrote:
> > Are you sure the input was type="filefield"
>
> I suspect you meant: type="file"

Whoops. Yes, I was confusing the HTML attribute with the CGI.pm
shortcut that generates that HTML. Thanks for catching that.

Paul Lalli



Posted by Gunnar Hjalmarsson on January 5, 2006, 8:16 pm
Please log in for more thread options


Paul Lalli wrote:
> kalikoi@gmail.com wrote:
>>
>> # Strip off WINDOZE path crap
>> $_=$filehandle;
>> s/.*\//;
>> my $filename=$_;
>
> Yuck. perldoc File::Basename

Nope. File::Basename wouldn't know from which platform the file was
sent, would it?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Similar ThreadsPosted
file upload, multipart form, and cgi::cache April 21, 2006, 7:01 am
File::FilterFuncs almost ready to upload to CPAN. January 18, 2007, 10:22 pm
Net:TFTPd questions - Want to upload configs via TFTP July 20, 2006, 12:29 pm
Choosing a good namespace for a module to upload to CPAN July 14, 2004, 1:46 pm
install HTML::Template - Problem reading cache file / Bad file number July 24, 2004, 7:55 pm
Reading contents of an excel file from a test file May 15, 2007, 2:49 am
A do-file location: how the code inside that do-file find it? January 20, 2008, 12:32 am
DBD:mysql doesn't read mysql option file /etc/my.cnf file January 27, 2005, 11:19 pm
Win32::File August 29, 2004, 9:08 pm
SGI::FAM and File::PathConvert June 14, 2005, 10:58 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap