in reply to Image Upload

Okay ... There seems to be a couple of issues here - The first is the location of the file which you are looking to upload. From the code snippet you have given us, it would appear that the file is already on the web server and it from from there that it is to be uploaded elsewhere - This however, is not what I think you are wanting to achieve. From comments in your code, it looks like you are wanting to upload a file from the web client's machine to the web server, something which the code above is unable to perform - The reason for this is because this CGI code when executed is executed on the web server and not on the client's machine. As such, all references to files residing on the client system are invalid.

As the author of CGI::Upload however, I would think that it should be able to do exactly what you desire - For example, the snippet of code returns a file handle to the file uploaded through the file input field named 'form_file_upload_field' on your HTML form:

use CGI; use CGI::Upload; my $cgi = CGI->new; my $upload = CGI::Upload->new($cgi); my $fh = $upload->file_handle('form_file_upload_field');

In addition to this, example usage of this module can be seen in this thread - If you have any questions regarding the CGI::Upload module, please feel free to contact me via email or /msg.

 

Replies are listed 'Best First'.
Re: Re: Image Upload
by tachyon (Chancellor) on Apr 03, 2002 at 08:43 UTC
    use CGI::Simple qw(-upload); my $q = new CGI::Simple; my $ok = $q->upload( $q->param('upload_file'), '/path/to/write/file.na +me' ); print "Uploaded ".$q->param('upload_file')." and wrote it OK!" if $ok;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Image Upload
by kappa (Chaplain) on Apr 03, 2002 at 12:02 UTC
    If I understand the original intentions right, the author tries to ftp-upload the newly-http-uploaded files. We used this technique once to achieve more security. The problem was that the uploading (or better say 'handling-the-form-with-a-file-attached') CGI script was running as user www. That's the usual case under Apache without suExec. So we had to permit www user to write to the directory where user-uploaded files were to reside.
    And we used another idea instead. When we get a http-uploaded file somewhere in the /tmp dir (CGI.pm scripts usually do), we just ftp-upload it to our own directory. This method let us not to give away our own, say, /uploaded-images dir to www user, which, of course, was the owner of all CGI processes on that machine.
Re: Re: Image Upload
by emilford (Friar) on Apr 03, 2002 at 19:50 UTC
    Thanks for the reply and sort of pointing out my mistake. So basically, the error that I'm getting "No such directory" is referring to the directory on the remote server, right?

    I went ahead and looked at the threads you recommened and started going through some of the code. The code that you mentioned above, creates the file handle...can that then be used with my $ftp->put('the file handle')?

    Sorry if this question is trivial, but I'm relatively new to perl. I guess asking these questions at perlmonk.org helps me to learn new things....with perl, there certainly is always something I didn't know before!!!

    Any further insight on creating a !simple! upload script? Thanks in advance.