Okay. How would i go about in doing this.
Open file -> delete contents -> add new content -> display content
so far ive only been able to read and write.but not delete the contents.
Printable View
Okay. How would i go about in doing this.
Open file -> delete contents -> add new content -> display content
so far ive only been able to read and write.but not delete the contents.
You can open the file in truncated write mode. Whereby the file contents is wiped when you open it.
PHP Code:$f = fopen('file/path', 'wb');
thanks...
Another question that goes along this line.
how would i go about in.... creating a file that doesnt exist. when the page loads...
heres my code.
all files are put to 0777
PHP Code:<?php
$filename = "empty_page.php";
$somecontent = "test\r\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'wb')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
If the file doesn't exists, fopen will always try to create it.
pfft...
now it works...
lol... i left it alone for 15 mins ... and come back to it... and it works... OoOo Scary. o.O
okay another Question...
NO STEALY IDEA.
idk how to go about the deleting of the files. i tried unlink and unset.PHP Code:if($_GET['page'] == ""){
$sql="Select * from pages WHERE name = 'home'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)):
///////////////////////////////////////////////////////
$filename = $_GET['page'] . ".php";
$somecontent = "$row[content]";
// Let's make sure the file exists and is writable first.
if (!$handle = fopen($filename, 'wb')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
chmod("$filename", 0777);
///////////////////////////////////////////////////////
include("$filename");
unlink($filename);
endwhile;
as you can see i even chmod the file to 0777.
Once i get the basics down... ill be able to be more creative...
Does it come up with an error message? Maybe the include call which opens that file maintains a lock on the file until the PHP process have finished.
again... after i leave it alone... it fixes itself...
*** IS UP WITH THAT?.lol