So, I'm trying to write a PHP script to open a text file and edit it. I've made all the permissions 777, and I still get:
Warning: fopen() [function.fopen]: failed to open stream: Permission denied in [directory] on line 3
I can't seem to figure out why this isn't working. Any suggestions would be appreciated.
Could you post your fopen() code and the file path/variable?
Sounds like you have the wrong path name. Could you show us some code and maybe a "pwd" from the server in the directory the file is at?
The code is very simple:
No matter what I do, as long as I'm not just trying to read the file (fopen(file, r)) I get the same error:Code:<?php echo getcwd(); $fp = fopen("tuesdayR.txt", "w+"); fclose($fp); ?>
E:\users\orchestra\Rehearsals
Warning: fopen(tuesdayR.txt) [function.fopen]: failed to open stream: Permission denied in E:\users\orchestra\Rehearsals\testPHP.php on line 3
Warning: fclose(): supplied argument is not a valid stream resource in E:\users\orchestra\Rehearsals\testPHP.php on line 4
PHP Warning: fopen(tuesdayR.txt) [function.fopen]: failed to open stream: Permission denied in E:\users\orchestra\Rehearsals\testPHP.php on line 3 PHP Warning: fclose(): supplied argument is not a valid stream resource in E:\users\orchestra\Rehearsals\testPHP.php on line 4
Last edited by FlyByWire128; 07-24-2007 at 05:21 AM. Reason: Forgot something...
Try adding the path:
Code:$fp = fopen("E:\\users\\orchestra\\file\\path\\here\tuesdayR.txt", "w+");
I tried adding the whole path as suggested, but no luck. It's still telling me permission denied, and I can't figure out why... Every suggestion I've ever heard when this happens is to change the permissions, but they're all set, so that shouldn't be a problem. Any other suggestions?
Have you tried a different file? Maybe it isn't the file permissions but the directory permissions. I've ran into this on Windows Machines before.
How did you change the permission to 777 in Windows? You mean you just made it world?
I've tried different files, I've tried different directories, I've tried files that already exist, I've tried creating a new file using fopen(). I'm using SmartFTP, and according to it, the directory, and the files are all 777 permissions... I don't know what else to do.
Post the results of this...Code:$filename = "tuesdayR.txt";
echo realpath($filename);
$filename = realpath($filename);
if (is_readable($filename)) {
echo "<br />The file is readable...<br />";
} else {
echo "<br />The file is not readable...<br />";
}
if (is_writable($filename)) {
echo "The file is writable...<br />";
} else {
echo "The file is not writable...<br />"
}
if (file_exists($filename)) {
echo "File exists...<br />";
} else {
echo "File cannot be found...<br />";
}
$handle = fopen($filename, "w");
fwrite($handle, 'Yo, sup?');
fclose($handle);
Last edited by John; 07-24-2007 at 03:34 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks