Log in

View Full Version : File not opening in php



thathoo
12-02-2006, 10:58 PM
Hi.
I have my home directory on my departments server. Somehow I am not
able to write to a file using a php code,
$myFile = "trial3.txt";
$fh = fopen($myFile, "a+") or die("can't open file");
fwrite($fh, "teststring\n");
fclose($fh);

Instead of a+ if i use r or w or anything, it does not work. Could this
be a permission thing? The entire directory had a 777 permission and
even i after i created a file and chmod'ed 777 to it, the code couldnt
open it. What could be the matter? It doesnt go away if i change it to
'w' or 'w+' or 'r' or 'r+'.

When i use the shell to parse the php script, it does actually write it to the file. But not when i open the url in the browser. What could be the matter?

Rahul

ItsMeOnly
12-02-2006, 11:43 PM
If I recall correctly fopen requires full path to file to work, unless you set third parameter to true (use_include_path)

mburt
12-03-2006, 12:16 AM
The file also has to be on the remote server you're working on. I don't think using the full path will be any use either, using what I previously said to back it up.
So. Put the file in your remote directory, or folder.

thetestingsite
12-03-2006, 12:22 AM
also, make sure that the directory has writable permissions or is at least owned by the same user as the PHP is running on your machine. I've run into this problem tons of times. If the directory was created by PHP, then it should be alright, but if it was not, you may have to chmod the directory to 777. Just a few suggestions.

mburt
12-03-2006, 12:56 AM
Oh yes. Exactly right, I forgot about that. It has to be 555 if made with PHP I'm pretty sure.