My code is:
$myFile = "test.html";
$fh = fopen($myFile, 'w') or die("can't open file");
I get the error:
Warning: fopen(test.html) [function.fopen]: failed to open stream: Invalid argument in ... can't open file
I have set write permissions, but I can't seem to get past this. What am I doing wrong?
[RESOLVED] Fopen error
ine the Warning it says "Invalid argument in" etc - is it referring to an invalid argument in the fopen() function ?
maybe you need to use double quotes instead of single ones (just a wild guess)
With the double quotes, the message is: failed to open stream: Permission denied. I'm stumped.
The quotes won't matter - without variables or escape sequences, a single-quoted string is exactly the same as a double-quoted string.
daltman1967 wrote:I'm stumped.
About what? The problem is quite clear:
daltman1967 wrote:Permission denied
PHP doesn't have the appropriate permissions to access the file.
I use filezilla, and I set permissions on the folder to 777 (all read/write), recursing both files & subdirectories. However, most of the files give a message 'command not understood' on the CHMOD command.
However, since the directory theoretically should be write accessible, and the file does not yet exist, how can file permissions be a problem... unless the file permissions still aren't set? I'm not sure what else to do.
PHP must have write permissions to the directory where you're trying to create the file. The error message is stating that it doesn't.
Therefore, it's unlikely that your FTP's CHMOD command succeeded. Are you sure the directory has 777 (or "drwxrwxrwx" if the FTP client displays permissions in that manner) permissions? Based on the PHP error message, I would have to guess that it does not.
EDIT: Also note that PHP has to have at least execute permissions on all directories above the one you're trying to write to. Then again, if you truly are trying to create a file in the same directory that the script is being executed in, it's a safe bet to assume this is already true.
Thanks so much for your input. Apparently, filezilla can't adjust the permissions of the directories directly; this is because the directories are set to inherit from the parent, and filezilla can't modify the parent. I had to go in through godaddy's file manager and set the parent's permission, and then set the children to inherit. Voíla! The file wrote perfectly. Now if I can get everything else figured out...