Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

using die in CGI context / 500 errors

by Baz (Friar)
on May 09, 2002 at 20:49 UTC ( [id://165503]=perlquestion: print w/replies, xml ) Need Help??

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

The following line gives me an error if I run it using my browser-IE6, but it works when run from the command line.
open(LOCAL, ">$dir/$name") or die $!;
this line works for both
open(LOCAL, ">$dir/$name");
THe browser error is 500 Internal Server Error
I can't check my error_log at the moment because its causing pico to crash. Anyway maybe someone has an idea!

Edit kudra, 2002-05-10 Changed title per ntc

Replies are listed 'Best First'.
Re: using die
by JayBonci (Curate) on May 09, 2002 at 21:01 UTC
    Die will cause your browser to fail on execution of the script. Add:
    use CGI::Carp(fatalsToBrowser);
    It's likely your web browser doesn't have permission to read the file and is dying because of that. Also try
    open(LOCAL, ">$dir/$name") or print $!;
    Good luck.

        --jb
Re: using die
by Zaxo (Archbishop) on May 09, 2002 at 21:05 UTC

    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

      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
Re: using die
by tune (Curate) on May 09, 2002 at 20:57 UTC
    Then use any of less/more/vi/emacs to view your error_log.

    --
    tune

Log In?
Username:
Password:

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

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

    No recent polls found