Page 1 of 1

fopen() can't open file?

Posted: Sun Jan 25, 2004 8:17 pm
by SteveO
can anyone tell me why this might not be able to open a file that is chmoded 777?

Code: Select all

$filename = "/home/webkin/public_html/news.php";

$username = $_POSTїusername];
$usernews = $_POSTїusernews];
if ($username == "") {
	header( "Location: newssubmit.php");
}
if ($usernews == "") {
	header( "Location: newssubmit.php");
}
$addtofile = "";
$addtofile .= "$username says:<br>/n
$usernews <br>";
$addtofile .= "-- date(Mjy)";
$filepointer = @fopen($filename, "W+") or die("couldnt open file");
@fwrite($filepointer, $addtofile) or die("Couldn't add news to $filename");
$msg = "<p>News was successfully added to $filename.</p>";
fclose($filename);
also, could anyone tell me what the @ symbol does in front of a function? It was in my PHP fast and easy web development book, so i just wrote it the same way... hoping it would work, i've tried everything that i can think of.

Posted: Sun Jan 25, 2004 9:57 pm
by DuFF
Try changing the "W+" to "w+", PHP is sometimes grouchy about the case. If that doesn't work, try taking out the @ and the or die() so that it looks like this:

Code: Select all

<?php
$filepointer = fopen($filename, "w+");
?>
What the @ sign does is suppress any error that PHP might try to give. Then by adding the "or die("couldnt open file")" it will automatically print out "couldn't open file" if there is any error.

Posted: Sun Jan 25, 2004 10:25 pm
by SteveO
yeah but the date() function doesn't work either... can anyone help with that?

Posted: Sun Jan 25, 2004 10:42 pm
by SteveO
and thanks duff, its writing to the file, but its producing a mass of errors. and exporting them to a file.

Posted: Mon Jan 26, 2004 10:16 am
by SteveO
oooh, i fixed it, i misspelled a variable in the fopen command....