Forum Moderators: coopster
------
Warning: fopen(files/testFile.txt): failed to open stream: File exists in ***/tests/fc.php on line 7
Warning: fwrite(): supplied argument is not a valid stream resource in ***/tests/fc.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in ***/tests/fc.php on line 11
Warning: fopen(files/testFile.txt): failed to open stream: Permission denied in ***/tests/fc.php on line 15
------
I tried it, no luck, then I tried it after having my files folder Chmodded to 777,but still no luck.
The file exists, but something wont happen, andI don't know what or how.
Advice / tips / solutions on this is greatly appreciated
[edited by: StickeR at 9:34 pm (utc) on Aug. 21, 2006]
Is the file accessible directly as a URL from you website. This has nothing to do with the problem at hand, but it can be a security problem. Someone could put some kind of mal-ware in this file if it is accessible as a URL.
Hope this helps.
<?php
$filename = 'files/testFile.txt';
$Content = "Add this to the file\r\n";
echo "open";
$handle = fopen($filename, 'x+');
echo " write";
fwrite($handle, $Content);
echo " close";
fclose($handle);
if($handle = fopen($filename, 'a')){
if(is_writable($filename)){
if(fwrite($handle, $content) === FALSE){
echo "Cannot write to file $filename";
exit;
}
echo "The file $filename was created and written successfully!";
fclose($handle);
} else{
echo "The file $filename, could not written to!";
exit;
}
} else{
echo "The file $filename, could not be created!";
exit;
};
?>
[ww.php.net...]
Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL¦O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.
so it is doing exactly as it is supposed to.
if you change this line
$handle = fopen($filename, 'x+');
to use a different mode, depending on what you want to do with the file, then it should work