I'm creating a file in CGI (Perl), but after it's created via the script, I can't replace it or chmod it.
What's the correct way to create a file in perl?
Printable View
I'm creating a file in CGI (Perl), but after it's created via the script, I can't replace it or chmod it.
What's the correct way to create a file in perl?
okay, I'm using this code to create the file:
Should I be using something else?Code:open(NEWFILE,">".$filename);
print NEWFILE $text;
close NEWFILE;
Hey, here's what you want:
if you need more help, my AIM sn is mexicanok.Code:open(FILE, ">>$file") or die "couldn't open file: $!";
print FILE "Blah Blah balh\n";
close(FILE);
What you're actuallin doing is erasing the old content of the file and adding $text, you want to use >> which appends to the file. I hope that helps, don't forget to IM me if you need more help.
Ok, i'm sorry.. i missunderstood your question......
You can create a file like you did. but add the "or die" part so you can identify the error. to chmod it just use the chmod function.
I think you're still misunderstanding me.
When I create the file, and then say I try to replace it by uploading a different copy of it, it won't let me.
Why is this?
I still don't know what you mean. I'm just gonna post some code to see if it helps.
I hope that helped.Code:#Create a file, if $file already excists, it erases
#whatever it had, and save $content.
open(FILE,">$file") or die "Coundn't open $file: $!";
print FILE $content;
close(FILE);
#append to the file
open(FILE,">>$file") or die "Couldn't open $file: $!";
pring FILE $content;
close(FILE);
The first example is what I am using.
Say I create a file called file1.txt with that code. When I try to upload file1.txt (and replace the one created) it won't let me. I can, however, delete it and then upload it.
Show me some more code (replacing the file) and why doesn't it let you?
There is no code to upload the file, it's uploaded by FTP (sorry I neglected that)
Is there anyway you could help me with my other CGI problem (with cookies) posted in this forum?
You running Apache on *nix? The Perl script might be run as a different user than what you're logging on as - a "nobody" account, or an "apache" account. I believe the "chown" command can fix this, but its been a while since I've seriously used *nix.
My email address is [email protected], Ask anything you want, i'll always reply, I just don't check this too much.