Page 1 of 1

Write to .txt file

Posted: Sun Aug 14, 2005 3:07 pm
by tetuanrp
I have just started using php on my mac os x and I'm going through a tutorial in a book using php with flash. I'm on the first excersize and having trouble already. Think it could be a configuration issue but thought I'd see if anyone could see a simple fix. Here is the php code that I'm using, which the book has given me.

Code: Select all

<?php
foreach ($_POST as $key=>$value) {
  $received .= "$key = $value\r\n";
  }

$printout = fopen("variables.txt", "w");
fwrite($printout, $received);
fclose($printout);
?>
When I run it I get this:
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Warning: Unknown: Failed opening '/Users/Admin/Sites/phpflash/ch02/feedback.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in Unknown on line 0

Is there something wrong with the file location and is that why its not creating a .txt file?

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Aug 14, 2005 3:43 pm
by John Cartwright
Most likely you have not set the proper permission through chmoding.. :arrow: chmod()

Posted: Sun Aug 14, 2005 5:35 pm
by bokehman
Try

Code: Select all

fopen("variables.txt", "w+")

Posted: Sun Aug 14, 2005 8:44 pm
by tetuanrp
Hmm. Didn't seem to work. I put it up on my hosts server which seems to run my scripts fine, and it spits back "sent=OK" now. So it seems like its processing fine but it still doesnt create a .txt file. I set the chmod permissions to 755 on the folder that the php file is in as well.

Posted: Sun Aug 14, 2005 9:44 pm
by tetuanrp
So I've got it working locally now, although on my remote server its not creating the file. Is setting the folder to 755 the correct permissions? (these are probably rookie questions, as that's exactly what I am!)

Posted: Mon Aug 15, 2005 3:38 am
by bokehman

Code: Select all

if($printout = fopen("variables.txt", "w") and fwrite($printout, $received) and fclose($printout){
	print 'I created and wrote to variables.txt.';
}else{
	 print 'I either could not create or write to variables.txt.';
}

Posted: Mon Aug 15, 2005 12:02 pm
by timvw
tetuanrp wrote:So I've got it working locally now, although on my remote server its not creating the file. Is setting the folder to 755 the correct permissions? (these are probably rookie questions, as that's exactly what I am!)
What do you think 755 ( drwxr-xr-x) does on a directory?

Does the webserver need read access on the directory to write into a directory? No.
Does he need write access? Yes.
Does he need execute/access to the directory? Yes.

Thus: you need -wx for the webserver..