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

Hi, I'm having problem getting perl script to write a file on the server. At command line, I typed: perl -ws filename.pl And it works fine, and file was created successfully. If I run it in a browser, it will not work. I have set the permissions to the directories so that users can write files to it. Any suggestions on how to solve this problem?

Replies are listed 'Best First'.
Re: file writing permission
by friedo (Prior) on Nov 24, 2006 at 03:41 UTC
    You'll need to look in your web server's error log to find out what went wrong.
Re: file writing permission
by madbombX (Hermit) on Nov 24, 2006 at 04:38 UTC
    You might also consider showing us the section of code that isn't writing the file. Are you checking the return values of the file I/O functions? eg:
    open $fh, '>', "/tmp/blah" or die "File Open Problem: $!";

    You could always have the or write to a log file somewhere that you are positive the web server has write access to (which is likely to be /tmp on most *nix machines). Also, I don't know what the script is for, but if it is a CGI that returns to the user, you could always debug by adding the following to the beginning of the script:

    use CGI::Carp qw(fatalsToBrowser);
      open $fh, '>', "/tmp/blah" or die "File Open Problem: $!";

      Whenever you die because of some error, always include both, the reason and the filename! This makes the error diagnosis and remedy much much faster in my experience:

      open $fh, '>', "/tmp/blah" or die "File Open Problem with '/tmp/blah': + $!";
Re: file writing permission
by alpha (Scribe) on Nov 24, 2006 at 08:01 UTC
    You said that you try to run it from browser.. Check if it does return correct headers.