Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

saving the file uploaded...

by PriNet (Monk)
on Feb 28, 2002 at 19:10 UTC ( [id://148333]=perlquestion: print w/replies, xml ) Need Help??

PriNet has asked for the wisdom of the Perl Monks concerning the following question:

i hate to be a pain, but, i really thought i had it this time.... having trouble saving the file that was submitted from the previous page (help?....again....)
#!/usr/bin/perl use strict; use CGI qw/:standard/; ############################################################## ### Variable Definitions ### ############################################################## my($FileHandle) = ""; my($FileStream) = ""; ############################################################## ### Main Program Begins Here ### ############################################################## $FileHandle = CGI->new; $FileStream = $FileHandle('AUT_File'); open (OUTFILE, ">test.jpg"); print OUTFILE $FileStream; close (OUTFILE);

Replies are listed 'Best First'.
Re: saving the file uploaded...
by Sinister (Friar) on Feb 28, 2002 at 19:32 UTC
    question 1: is your form set with ENCTYPE="formdata/multi-part" ?

    Yes :
    CGI returns a magic GLOB for you.
    $FileHandle = GGI::->new(); $FileStream = $FileHandle->('AUT_file');
    gives you an actual GLOB. However, if you do:
    print $FileStream,"\n";
    you'll notice that is prints the filename. If you do:
    print <$FileStream>,"\n";
    you'll notice it will print the file-data.

    No :
    Fix that - (eg: <form METHOD="POST" ACTION="my_script.cgi" ENCTYPE="formdata/multi-part"> ) and then read part 'Yes'



    Sinister greetings.
    "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
    perldoc -q $_
      earthboundmisfit thanx for that one, that fixed my internal server error... and Sinister ?... too cool, it worked ! ( i was using the right encrypt... thanx for noting...)(for a jpg anyway) gonna run with it...thanx guys.... Final Code:
      #!/usr/bin/perl use strict; use CGI qw/:standard/; ############################################################## ### Variable Definitions ### ############################################################## my($FileHandle) = ""; my($FileStream) = ""; ############################################################## ### Main Program Begins Here ### ############################################################## $FileHandle = CGI::->new(); $FileStream = $FileHandle->param('AUT_File'); open (OUTFILE, ">test.jpg"); print OUTFILE <$FileStream>; close (OUTFILE);
      hey, i was close... *heh* thanx again everyone... i been trying this "feature" for my gallery for weeks....lol -gary
Re: saving the file uploaded...
by screamingeagle (Curate) on Feb 28, 2002 at 19:23 UTC
    my guess is that since you're initializing the filestream variables as scalars, this might be preventing it from acting as a filehandle...try removing the initializing lines...
      my $scalar = ''; $scalar = {}; print ref $scalar, "\n"; $scalar = []; print ref $scalar, "\n"; use IO::File; $scalar = IO::File->new(); print ref $scalar, "\n";
      Update: Perl is loosely typed. Assignments tend not to care about the previous contents of the variable. That's all.
        That may be true, however, i had a very similar problem a few months ago, which i fixed by removing the initialization line... hence my post :-)
Re: saving the file uploaded...
by earthboundmisfit (Chaplain) on Feb 28, 2002 at 19:23 UTC
    I'm not too familiar with saving uploaded files, but don't you want:
    $FileStream = $FileHandle->param('AUT_File');
      The upload() method is the recommended means to get a filehandle. It was added in version 2.47 (quite a while back). The OP might also want binmode, if his platform warrants it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://148333]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found