I am trying to write to a file when running the following Perl/CGI script:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hi";
open(FILE,">hello.txt") || die("Cannot Open File");
print FILE "Hello";


I have run the script from the command line and "hello.txt" does appear but if I run the script from a Web Browser, "hello.txt" does not get created.
I have a feeling I need to change or add something to httpd.conf but don't know what it could be.

It could be a problem of permissions.
If it is, your script should die and you should find an error message in your log file (probably /private/var/log/httpd/error_log )


The web server is running under a different user account than yourself and has only limited permissions (for security reasons).

You should also include the error message in your "die" message:
die "cannot open file: $! ";


Other hints:


- use strict
- close the file when done
- use CGI::Carp qw(fatalsToBrowser)


The last one will send error messages to your web browser, so you do not have to go through the error log file.



Cheers,



Thilo




Reply via email to