Forum Moderators: coopster

Message Too Old, No Replies

Problem writing files using fwrite()

         

Blitz

10:23 am on Aug 15, 2004 (gmt 0)

10+ Year Member



My problem is that I'm trying to write a file using the fwrite() function, but I get this error:

Warning: fopen(): Unable to access test.html in /home/sc256/www/scripts/add.php on line 12

Warning: fopen(test.html): failed to open stream: No such file or directory in /home/sc256/www/scripts/add.php on line 12

Warning: filesize(): Stat failed for test.html (errno=2 - No such file or directory) in /home/sc256/www/scripts/add.php on line 13

Warning: fread(): supplied argument is not a valid stream resource in /home/sc256/www/scripts/add.php on line 13

Warning: fclose(): supplied argument is not a valid stream resource in /home/sc256/www/scripts/add.php on line 14

The code I'm using is:

<?php

$stuff = ("
<b>$category Reviews -$title-</b><br><br>
[Author: $author]<br>
[Permission granted for use]<br><br>
$review");

$filename = $title . ".html";
$create = fopen(filename, "w");
fclose($create);
$file = fopen($filename, "r");
$read = fread($file, filesize($filename));
fclose($file);
$blah = fopen($filename, "w"); //Leave alone look and learn, only edit if you know php
$news=stripslashes($news);
fwrite($blah, "$news $read");
fclose ($blah);

?>

All of the variables in $stuff is defined by a form that goes to this page. Help please?

mykel79

11:33 am on Aug 15, 2004 (gmt 0)

10+ Year Member



The first thing you should do is check if PHP has permission to write to the directory where test.html is to be placed. You can start by giving write permissions for that directory to all users and see if the script starts working.

Oras

1:48 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



Hi ...
I agree with mykel79 ...
go to Cpanel & give the permission 777 to the file & to the folder containing the file.
Oras