Click to See Complete Forum and Search --> : CGI - Create File
The Hobo
Mar 1st, 2002, 04:29 PM
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?
The Hobo
Mar 2nd, 2002, 11:12 AM
okay, I'm using this code to create the file:
open(NEWFILE,">".$filename);
print NEWFILE $text;
close NEWFILE;
Should I be using something else?
josegajefe
Mar 2nd, 2002, 04:27 PM
Hey, here's what you want:
open(FILE, ">>$file") or die "couldn't open file: $!";
print FILE "Blah Blah balh\n";
close(FILE);
if you need more help, my AIM sn is mexicanok.
josegajefe
Mar 2nd, 2002, 04:29 PM
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.
josegajefe
Mar 2nd, 2002, 04:32 PM
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.
The Hobo
Mar 3rd, 2002, 12:05 AM
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?
josegajefe
Mar 3rd, 2002, 09:53 AM
I still don't know what you mean. I'm just gonna post some code to see if it helps.
#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);
I hope that helped.
The Hobo
Mar 3rd, 2002, 04:53 PM
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.
josegajefe
Mar 3rd, 2002, 05:33 PM
Show me some more code (replacing the file) and why doesn't it let you?
The Hobo
Mar 3rd, 2002, 06:31 PM
There is no code to upload the file, it's uploaded by FTP (sorry I neglected that)
The Hobo
Mar 3rd, 2002, 06:33 PM
Is there anyway you could help me with my other CGI problem (with cookies) posted in this forum?
JoshT
Mar 4th, 2002, 11:01 AM
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.
josegajefe
Mar 4th, 2002, 03:12 PM
My email address is josegajefe@hotmail.com, Ask anything you want, i'll always reply, I just don't check this too much.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.