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
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