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.
PHP fopen() problems
Started by FlyByWire128, Jul 23 2007 07:53 AM
11 replies to this topic
#1
Posted 23 July 2007 - 07:53 AM
|
|
|
#2
Guest_Jordan_*
Posted 23 July 2007 - 09:48 AM
Guest_Jordan_*
Could you post your fopen() code and the file path/variable?
#3
Posted 23 July 2007 - 05:41 PM
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?
#4
Posted 23 July 2007 - 07:59 PM
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:
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
<?php
echo getcwd();
$fp = fopen("tuesdayR.txt", "w+");
fclose($fp);
?>
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:
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
#5
Posted 24 July 2007 - 07:29 AM
Try adding the path:
$fp = fopen("E:\\users\\orchestra\\file\\path\\here\tuesdayR.txt", "w+");
#6
Posted 24 July 2007 - 07:48 AM
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?
#7
Guest_Jordan_*
Posted 24 July 2007 - 08:18 AM
Guest_Jordan_*
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.
#8
Posted 24 July 2007 - 11:30 AM
How did you change the permission to 777 in Windows? You mean you just made it world?
#9
Posted 24 July 2007 - 12:02 PM
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.
#10
Posted 24 July 2007 - 01:16 PM
$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);
Post the results of this...
#11
Posted 24 July 2007 - 01:29 PM
The output to that was:
Fatal error: Can't use function return value in write context in E:\users\orchestra\Rehearsals\testPHP.php on line 27
PHP Fatal error: Can't use function return value in write context in E:\users\orchestra\Rehearsals\testPHP.php on line 27
If I take out the last 3 lines of code, I get:
E:\users\orchestra\Rehearsals\tuesdayR.txt
The file is readable...
The file is writable...
File exists...
Fatal error: Can't use function return value in write context in E:\users\orchestra\Rehearsals\testPHP.php on line 27
PHP Fatal error: Can't use function return value in write context in E:\users\orchestra\Rehearsals\testPHP.php on line 27
If I take out the last 3 lines of code, I get:
E:\users\orchestra\Rehearsals\tuesdayR.txt
The file is readable...
The file is writable...
File exists...
#12
Posted 24 July 2007 - 03:14 PM
How about this?
One of my favorite things to do when I have a problem I cant solve is to use "debug statements" to find precisely where the the problem is.
Edit:
Also please post these:
PHP Version
Web server software [apache or IIS] and version
Operating System
Safemode enabled/disabled
$filename = "tuesdayR.txt";
$filename = realpath($filename);
$content = "Yo sup!\n";
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($content) to file ($filename)";
fclose($handle);
One of my favorite things to do when I have a problem I cant solve is to use "debug statements" to find precisely where the the problem is.
Edit:
Also please post these:
PHP Version
Web server software [apache or IIS] and version
Operating System
Safemode enabled/disabled


Sign In
Create Account


Back to top









