Home > Archive > PERL CGI Beginners > September 2005 > problems with CGI.pm upload feature
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problems with CGI.pm upload feature
|
|
| Scott R. Godin 2005-09-16, 6:55 pm |
| script is at http://phpfi.com/78748
I followed the instructions in CGI.pm as best I could, and from what I read the
upload() function is supposed to return a filehandle ? (it doesn't say whether
this is a direct FH to the tempfile or not)
I had dome some preliminary testing with one-liners and was pretty sure this
would work, but what I wind up with in the attachment is a file containing the
name of the file, not its actual contents.
what did I do wrong? I can't figure it out. :/
| |
| Wiggins d'Anconia 2005-09-16, 9:55 pm |
| Scott R. Godin wrote:
> script is at http://phpfi.com/78748
>
> I followed the instructions in CGI.pm as best I could, and from what I
> read the upload() function is supposed to return a filehandle ? (it
> doesn't say whether this is a direct FH to the tempfile or not)
>
> I had dome some preliminary testing with one-liners and was pretty sure
> this would work, but what I wind up with in the attachment is a file
> containing the name of the file, not its actual contents.
>
> what did I do wrong? I can't figure it out. :/
>
Just because it is easy to overlook and fairly common, did you include
the 'enctype' in the form tag? For instance,
[form enctype="multipart/form-data" action="/cgi-bin/request" method="POST"]
HTH,
http://danconia.org
| |
| Scott R. Godin 2005-09-17, 7:55 am |
| Wiggins d'Anconia wrote:
> Scott R. Godin wrote:
>
>
>
> Just because it is easy to overlook and fairly common, did you include
> the 'enctype' in the form tag? For instance,
>
> [form enctype="multipart/form-data" action="/cgi-bin/request" method="POST"]
>
Good call, but yeah I did make sure that got done. It's good to point that out
as unless you generated the form with CGI.pm itself, it's easy to miss.
| |
| Bill Stephenson 2005-09-17, 6:55 pm |
| On Sep 16, 2005, at 7:51 PM, Scott R. Godin wrote:
[color=darkred]
> Wiggins d'Anconia wrote:
Possibly used the wrong web browser to upload the file. Not all of them
support this feature. Firefox does not. It will however provide the CGI
script with the file name.
Kindest Regards,
--
Bill Stephenson
| |
| Wiggins d'Anconia 2005-09-17, 6:55 pm |
| Bill Stephenson wrote:
> On Sep 16, 2005, at 7:51 PM, Scott R. Godin wrote:
>
>
>
> Possibly used the wrong web browser to upload the file. Not all of them
> support this feature. Firefox does not. It will however provide the CGI
> script with the file name.
>
> Kindest Regards,
>
> --
> Bill Stephenson
>
>
Firefox doesn't support file uploads? I use it all the time to test
scripts that accept uploads.
Huh?
http://danconia.org
| |
| Scott R. Godin 2005-09-18, 8:01 am |
| Wiggins d'Anconia wrote:
> Bill Stephenson wrote:
[color=darkred]
>
> Firefox doesn't support file uploads? I use it all the time to test
> scripts that accept uploads.
>
> Huh?
>
It'd be news to me too -- I've used firefox for uploads plenty of times.
| |
| Scott R. Godin 2005-09-19, 7:55 am |
| Scott R. Godin wrote:
[color=darkred]
>
>
> It'd be news to me too -- I've used firefox for uploads plenty of times.
Regrettably this isn't getting me any closer to a resolution -- what about the
code? can anyone see anything I might have overlooked? done wrong? should it, in
fact, be working right now?
I had hoped this would be pretty straightforward, and tried my best to follow
the examples in the docs and sample files, but I'm at a complete dead-end here.
Anyone?
| |
| Charles K. Clarkson 2005-09-19, 6:55 pm |
| Scott R. Godin <mailto:nospam@webdragon.net> wrote:
: Regrettably this isn't getting me any closer to a resolution --
: what about the code? can anyone see anything I might have
: overlooked? done wrong? should it, in fact, be working right
: now?
Did you test to be certain that @file actually holds the contents
of the uploaded file?
use CGI::Carp 'fatalsToBrowser;
my @file = <$fields{file_attached}>;
die @file;
Use a small file for the test.
: I had hoped this would be pretty straightforward, and tried my
: best to follow the examples in the docs and sample files, but
: I'm at a complete dead-end here.
:
: Anyone?
I haven't looked at the docs but shouldn't 'Data' be set to
an array reference, not an array?
$message->attach(
Type => 'AUTO',
Data => @file,
Disposition => 'attachment',
Filename => param('file_attached'),
Encoding => 'base64',
);
Use:
Data => \@file,
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| Scott R. Godin 2005-09-20, 7:55 am |
| Charles K. Clarkson wrote:
> Scott R. Godin <mailto:nospam@webdragon.net> wrote:
>
> : Regrettably this isn't getting me any closer to a resolution --
> : what about the code? can anyone see anything I might have
> : overlooked? done wrong? should it, in fact, be working right
> : now?
>
> Did you test to be certain that @file actually holds the contents
> of the uploaded file?
>
> use CGI::Carp 'fatalsToBrowser;
> my @file = <$fields{file_attached}>;
> die @file;
>
> Use a small file for the test.
>
>
> : I had hoped this would be pretty straightforward, and tried my
> : best to follow the examples in the docs and sample files, but
> : I'm at a complete dead-end here.
> :
> : Anyone?
>
>
> I haven't looked at the docs but shouldn't 'Data' be set to
> an array reference, not an array?
>
> $message->attach(
> Type => 'AUTO',
> Data => @file,
> Disposition => 'attachment',
> Filename => param('file_attached'),
> Encoding => 'base64',
> );
>
> Use:
>
> Data => \@file,
>
That didn't work, but changing 'Data' to 'FH' did work, instead of slurping the
file into an array, I passed the filehandle directly to the object's attach method.
Later, I additionally changed the Type to "BINARY" as MIME::Types doesn't seem
to be installed on the system, (as Yahoo's mail attachment scanner showed the
file type as 'auto/' for some reason), and everything still seems to be working
fine.
now everything seems to be hunky dory. Don't know why it made a difference. but
at least it works now. *headdesk*
|
|
|
|
|