Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Create a file with Perl

by BastardOperator (Monk)
on Sep 17, 2000 at 05:55 UTC ( [id://32845]=note: print w/replies, xml ) Need Help??


in reply to Create a file with Perl

Assuming that you're using some flavor of unix, your problem probably lies in the fact that the cgi is running as user "nobody", and most likely does not have permission to write to the directory. Depending on the directory that you're writing to I'd be careful about just chmod 777'ing it also. You may want to create a subdirectory just for the purpose of writing to from that cgi. Also, you could most likely just use open() to do this, which is the generally preferred method. sysopen() allows better control, but I'd assume that the permissions you're trying to give the file are the default anyway, so maybe just try:
open(FH, "> $myfile") || die "Can't open $file for write: $!";

Replies are listed 'Best First'.
RE: Re: Create a file with Perl
by Anonymous Monk on Sep 17, 2000 at 06:13 UTC
    Does that mean there is nothing I can do to get the script to do this automatically? The script needs to create a brand new file and I don't want the user to have to do this. If the user has to stop and create their own file every time the script is run, it is useless. I tried

    open(FH, "> $myfile") || die "Can't open $file for write: $!";

    to create a new file, but it still gave me "permission denied" . Is there something weird I can do with setuid or something to change the user the script is running as?

    By the way, thanks for answering!

      No, what I said was that you would need to create a directory ahead of time in which those files will be created. The directory needs to have proper permissions most likely 777, but if the data that they are writing is somehow sensitive, you'll need to make the nobody user the owner of the directory and give it 755 permissions. Then, instead of
      open(FH, "> $myfile") ...
      do
      open(FH, "> somedirectorytheycanwriteto/$myfile") ...
      If you're not worried about file persistence (for long periods) or data sensitivity, you can try placing the files in /tmp.
        If you want temporary files use File::Temp. There are a lot of reasons for my saying that, including avoiding a ton of potential security problems.

Log In?
Username:
Password:

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

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

    No recent polls found