in reply to Re^2: File upload under Apache2
in thread File upload under Apache2

Replies are listed 'Best First'.
Re^4: File upload under Apache2
by tospo (Hermit) on Aug 16, 2010 at 09:11 UTC

    I think the "How Not to Ask a Question" link is almost a little bit unsuitable in this case because the OP asked a clear question but seems to have been confused by online tutorials that cover PHP rather than Perl.

    @Bruce32903, I think the error you got when using the example posted above is most likey due to copying the path given in the example, which will (most likely) not exist on your system. Just change '/usr/local/web/users/feedback' to something that does exist on your system and make sure that you end up with a unique filename. For example, if you can identify your user by a user ID then you might want to write the uploaded file to

    'some/path/to/uploaded/files/USER_XXX/feedback'

    You only need to understand how to read and write files to the disk. When asked to upload a file, your web server will save the file in a temporary location on your filesystem and all you get from CGI is either a handle on that file (this is the first example in the first reply to your post) or the full name to the temp file (second example).

    Once you have that handle, you read from it like you would read from any other file on the disk in a "while (<FILEHANDLE>){..}" loop and you can either write to a new file or jsut do something with the informatin you got and let the system automatically dispose of the tmp file if you don't need to store it.

    Just one more thing: if you happen to be on Windows, you might need to add a line

    binmode OUTFILE;
    after the "open" statement in the example in the first reply. As far as I know, it doesn't do any harm to put it in just in case anyway.

      I think the "How Not to Ask a Question" link is almost a little bit unsuitable in this case because the OP asked a clear question but seems to have been confused by online tutorials that cover PHP rather than Perl.

      I don't see why since Bruce32903 spent about 20 minutes trying to get it to work.... and then he doesn't show his code.

      The fragment posted was an excerpt from the documentation Bruce32903 needs to read

        Yes, maybe the OP could have read a bit more documentation but sometimes this is very confusing for the beginner. File upload with CGI is a bit unintuitive at first because, intuitively, you expect to do some actual upload and it takes some time to realise that you are actually just copying a file that is already in some temp folder on local disk by the time you get to use it. Besides, the OP did show code but wasn't yet in a position to fully understand what it does. I think it is fair to ask for some hints in that case.