PDA

View Full Version : fopen works only in append mode


evolution-x
03-16-2008, 08:02 AM
Hello ;)

I'm facing a problem with using fopen command in php.
fopen($filename, 'a') - works fine (append mode)

BUT. I need to replace the contents of the file not add to it.
How do i do this?
fopen($filename, 'w') and fopen($filename, 'r+') - do not work (file not writable)

the code im using:

<?php
$filename = $_GET['item'].".txt";
$nr = $_GET['nr'];

if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $nr) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($nr) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>

I have set the files' permissions to 7777 (allow everyone to do everything)
Any ideas? :confused:


Thanks for reading.
Martin K

MaestroS
03-16-2008, 09:06 PM
1 second over Google:
http://www.thescripts.com/forum/thread684377.html

Man has same problem like you and it seems it's solved.

Secondly, if PHP has some accessibility problems, read them using:

error_reporting(E_ALL);


Thirdly, as default, fopen() has full rights to work with 'a', 'a+', 'w', 'wb', 'r', 'r+' modes, so if you cannot manage any file, then some permission forbids it.