in reply to Runs from console but not as CGI - temp file not created
You don't mention what web server you're using, and that can make a big difference in one of several ways. First, different web servers are inconsistent in what working directory they launch scripts in. You'd expect that to be whatever directory the script itself is, but that's not always the case. (I recall pulling my hair out when trying to debug a script on Netscape FastTrack.)
Further, different OS/Web Server combinations have different notions of permissions. Since your problem may be one of writing, chances are good that you're using Apache on Unix or a Unix variant (e.g., Linux, FreeBSD). Here, to write a temporary file, the directory that holds the CGI must have a permission that allows whatever user the web server is running under to create a file. This isn't a "best practice". Better is to create a subdirectory that will hold only data, giving that subdirectory a "world writable" permission, and then creating the temporary file in that directory. Assuming that writeable subdirectory is "data", changing your code to
should be sufficient. The three-argument form of open() makes it explict that you're trying to create a file. The "or die" part will provide you with valuable information in your server logs should things fail.open(DA, ">", "data/date.tmp") or die "data/date.tmp: $!";
|
|---|