fopen: created file not editable, why?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lilsavgrad01
Forum Newbie
Posts: 9
Joined: Thu Jun 09, 2005 9:50 am

fopen: created file not editable, why?

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

You need to chmod your directory. Search this forum for chmod and directory privileges.
lilsavgrad01
Forum Newbie
Posts: 9
Joined: Thu Jun 09, 2005 9:50 am

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please post your code including your chmod() call.
lilsavgrad01
Forum Newbie
Posts: 9
Joined: Thu Jun 09, 2005 9:50 am

Post 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);
lilsavgrad01
Forum Newbie
Posts: 9
Joined: Thu Jun 09, 2005 9:50 am

Post by lilsavgrad01 »

in addition, I don't actually use the chmod command, I set the chmod when I used mkdir
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
lilsavgrad01
Forum Newbie
Posts: 9
Joined: Thu Jun 09, 2005 9:50 am

Post 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
Post Reply