in reply to using die in CGI context / 500 errors

Chances are that the server's cgi uid does not have write permission for $dir. You can try 'tail logfile' to see the most recent errors.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: using die
by Baz (Friar) on May 09, 2002 at 22:06 UTC
    Thanks guys, the error is that the directory of filename does not exist - this is in reponse to the die statement.
    Im guessing now that die isnt dandled by browsers and thats why I got the 500 error, Anyway....
    This is my code -
    #!/usr/local/bin/perl use strict; use CGI; my $query = new CGI; my $dir = $query->param('dir'); my $file = $query->param('file'); $file =~m/^.*(\\|\/)(.*)/; my $name = $2; open(LOCAL,">$dir/$name");# or die "Die: $!"; while(<$file>) { print LOCAL $_; } print $query->header(); print $query->start_html("File Upload"); # DEBUG TO SCREEN print "File and Dir: "$file; print "File: ",$name; print $query->end_html;
    THe program prints -
    File and Dir: C:\Documents and Settings\Barry Griffin\Desktop\verbs.tx +t File: verbs.txt
    The directory and file are located on my local machine, so i've no idea why I might be getting this error - im working on XP. ANy ideas?
      If the script is on a *NIX box (which given the #! line I can see it is) and you want to access local files you will need to set up some networking calls to access them. A better (and safer answer) would be to upload your files to a folder on your server and access them from there.

      John
        I see, so under what circumstances would the code I have written above work - I presumed it would let a client upload files to a server, but I also felt it looked much too easy - this is my first time doing any file uploading!. I wrote this code because I want to allow people to upload files to my server - these files will eventually be organised using MySql. WHat modifications will I need to make - security is a big issue too - is it possible to give someone enough access in order for them to upload a file without compromising server security - im sure it is. Anyway Thanks, Barry.
        This is the html I'm using to call the script -
        <HTML><BODY> <FORM ENCTYPE="multipart/form-data" ACTION="http://baz.perlmonk.org/co +okie.cgi" METHOD="POST"> Please choose directory to upload to:<br> <SELECT NAME="dir"> <OPTION VALUE="images">images</OPTION> <OPTION VALUE="sounds">sounds</OPTION> </SELECT> <p> Please select a file to upload: <BR> <INPUT TYPE="FILE" NAME="file"> <p> <INPUT TYPE="submit"> </FORM> </HTML></BODY>
        Quite off topic, but #! is not indicative of *nix. It's a nicety on a *nix box, but will not interfere with execution on other operating systems. (If it's not present in a *nix environment, the script can still be executed with perl script.pl.)

        If things get any worse, I'll have to ask you to stop helping me.