Page 1 of 1

fopen: created file not editable, why?

Posted: Thu Jun 09, 2005 1:56 pm
by lilsavgrad01
I am dynamically creating files using fopen("filename.php", 'a')

I'm able to actually create the files but when I go look at them through the ftp, the files cannot me manipulated. I cannot delete them, I can't put new files into the directory the file is in, and I can't delete the directory that the file is in. I've tried all kinds of things to put in place of 'a' in the fopen command, but nothing has made any difference.

Has anything like this every happened to anyone? Please help, I have no idea what to do anymore.

Posted: Thu Jun 09, 2005 2:52 pm
by hawleyjr
You need to chmod your directory. Search this forum for chmod and directory privileges.

Posted: Thu Jun 09, 2005 2:55 pm
by lilsavgrad01
that's the thing though, before I create the file I create the directory and I set the chmod to 777. and the file does get created there but once it's in there when I go to delete the file using my ftp program I am told that I don't have the permission.

now, I tried just creating the directory without putting a file into there and then I'm able to do whatever I want to the file, so it must me something having to do with how I'm creating the file itself.

Posted: Thu Jun 09, 2005 2:57 pm
by hawleyjr
Please post your code including your chmod() call.

Posted: Thu Jun 09, 2005 3:01 pm
by lilsavgrad01
thanks for checkin this out

Code: Select all

$directory = "../testPages/$DepartmentName";
if ( !$department_handle = mkdir($directory, 0777) )
{
	echo "Cannot create directory";
}
		
//creates default page
if ( !$file_handle = fopen($PageName,'a+b') )
{
	die("Cannot open file");
}
if ( !fwrite($file_handle, $PageContent) )
{
	die("Cannot write to file");
}
					
fclose($file_handle);

Posted: Thu Jun 09, 2005 3:02 pm
by lilsavgrad01
in addition, I don't actually use the chmod command, I set the chmod when I used mkdir

Posted: Thu Jun 09, 2005 3:04 pm
by hawleyjr
I'm not sure what your trying to do with "a+b"

did you look at the fopen() function?

http://us3.php.net/manual/en/function.fopen.php

Also check out calling umask(0) before the mkdir() call:

http://us3.php.net/manual/en/function.umask.php

Posted: Thu Jun 09, 2005 3:08 pm
by lilsavgrad01
yeah, I actually read through all of fopen and found that there's all kinds of things about using just "a" and then you can use "a+".. there's a whole listing and explanation there, and it looks like there are several ways to get this to work, but it's just not happening for me. because all of those settings have to do with the readability and writability of the file, it doesnt seem to have anything to do with whether the file should be deletable or not

thanks for the efforts