fopen() can't open file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

fopen() can't open file?

Post 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.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

Post by SteveO »

yeah but the date() function doesn't work either... can anyone help with that?
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

Post by SteveO »

and thanks duff, its writing to the file, but its producing a mass of errors. and exporting them to a file.
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

Post by SteveO »

oooh, i fixed it, i misspelled a variable in the fopen command....
Post Reply