On 6/8/05, Alex Brelsfoard <[EMAIL PROTECTED]> wrote:
> I know I asked a similar question a while back, but I'm compelled to try 
> again.
> 
> I have an existing script, not using CGI to take in parameters handed to the
> script.  I would now like to have this script upload a file to the server, but
> not be forced to convert the entire file to using CGI.

For the record, converting the entire file would probably be a Good Thing.

> This is the code I've used in the past:
> -------------------------------------------------------------
>         use CGI;
>         #create new instantiation of a form query.
>         my $query = new CGI;
> 
>         open (UPLOAD, ">$filepath") || &Error("Could not open file for 
> writing:
> $filepath");
>         my $picture = $query->upload('photo');
>         if ($picture) {
>                 while ($bytesread=read($picture,$buffer,1024)) {
>                         print UPLOAD $buffer;
>                 }
>         }else {
>                 &Error("Picture ($picture) is undefined.<br> File: 
> $photoName<br>For some
> reason I cannot read in this file.");
>         }
>         close (UPLOAD);
> -------------------------------------------------------------
> 
> But as you can see, it's using CGI.
> Any suggestions of how to upload an image similarly without having to rewrite
> the rest of my code?

Here is a stupid trick.

Slurp STDIN into a scalar.  Then use IO::Scalar to tie STDIN to that
scalar.  Open CGI, then you can seek to position 0 in STDIN, and
run your (probably worse) form handling code.

Ben
 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to