Odd behavior of fopen() in local directory
Posted: Fri Nov 03, 2006 9:56 pm
Community: I am trying to write to a file with fopen. I can confirm it's existence.
Here be my snippet. No matter the path descriptor, it won't open. fopen() is enabled - confirmed via phpInfo. Error output below code.
Output:
it's there
Warning: fopen(../slides/05B.php) [function.fopen]: failed to open stream: No such file or directory in C:\website\slides\publisher_rhp.php on line 79
Warning: fwrite(): supplied argument is not a valid stream resource in C:\website\slides\publisher_rhp.php on line 80
Warning: fclose(): supplied argument is not a valid stream resource in C:\website\slides\publisher_rhp.php on line 81
I'm not terribly experienced with php, but I'm not at all new to app servers either...
thanks for your consideration,
Elwoody
Here be my snippet. No matter the path descriptor, it won't open. fopen() is enabled - confirmed via phpInfo. Error output below code.
Code: Select all
<?php
// $filename = "C:\\website\\slides\\05B.php"; // this works for (a) and (b)
// $filename = "./05B.php"; // this works for (a) and (b)
// $filename = "../slides/05B.php"; // this works for (a) and (b)
$filename = "../slides/05B.php";
chmod ($filename, 777); // (a)
if (file_exists($filename)) { // (b)
echo "<br>it's there<br>";
} else {
echo "<br>it ain't there<br>";
}
$handle = fopen($filename, “r”); // (c) always fails
fwrite($handle, 'Yo, sup?'); // (d) always fails
fclose($handle); // (e) always fails
?>it's there
Warning: fopen(../slides/05B.php) [function.fopen]: failed to open stream: No such file or directory in C:\website\slides\publisher_rhp.php on line 79
Warning: fwrite(): supplied argument is not a valid stream resource in C:\website\slides\publisher_rhp.php on line 80
Warning: fclose(): supplied argument is not a valid stream resource in C:\website\slides\publisher_rhp.php on line 81
I'm not terribly experienced with php, but I'm not at all new to app servers either...
thanks for your consideration,
Elwoody