|
-
Mar 1st, 2002, 05:29 PM
#1
Thread Starter
Stuck in the 80s
CGI - Create File
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?
-
Mar 2nd, 2002, 12:12 PM
#2
Thread Starter
Stuck in the 80s
okay, I'm using this code to create the file:
Code:
open(NEWFILE,">".$filename);
print NEWFILE $text;
close NEWFILE;
Should I be using something else?
-
Mar 2nd, 2002, 05:27 PM
#3
New Member
Hey, here's what you want:
Code:
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.
-
Mar 2nd, 2002, 05:29 PM
#4
New Member
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.
-
Mar 2nd, 2002, 05:32 PM
#5
New Member
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.
-
Mar 3rd, 2002, 01:05 AM
#6
Thread Starter
Stuck in the 80s
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?
-
Mar 3rd, 2002, 10:53 AM
#7
New Member
I still don't know what you mean. I'm just gonna post some code to see if it helps.
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);
I hope that helped.
-
Mar 3rd, 2002, 05:53 PM
#8
Thread Starter
Stuck in the 80s
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.
-
Mar 3rd, 2002, 06:33 PM
#9
New Member
Show me some more code (replacing the file) and why doesn't it let you?
-
Mar 3rd, 2002, 07:31 PM
#10
Thread Starter
Stuck in the 80s
There is no code to upload the file, it's uploaded by FTP (sorry I neglected that)
-
Mar 3rd, 2002, 07:33 PM
#11
Thread Starter
Stuck in the 80s
Is there anyway you could help me with my other CGI problem (with cookies) posted in this forum?
-
Mar 4th, 2002, 12:01 PM
#12
Black Cat
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.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Mar 4th, 2002, 04:12 PM
#13
New Member
My email address is [email protected], Ask anything you want, i'll always reply, I just don't check this too much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|