|
-
Nov 10th, 2005, 04:46 AM
#1
Thread Starter
Hyperactive Member
fread/fwrite help
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.
Last edited by PlaGuE; Nov 10th, 2005 at 04:52 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 10th, 2005, 05:23 AM
#2
Re: fread/fwrite help
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');
-
Nov 10th, 2005, 05:30 AM
#3
Thread Starter
Hyperactive Member
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 11th, 2005, 02:36 AM
#4
Thread Starter
Hyperactive Member
Re: fread/fwrite help
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";
}
?>
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 11th, 2005, 03:01 AM
#5
Re: fread/fwrite help
If the file doesn't exists, fopen will always try to create it.
-
Nov 11th, 2005, 03:09 AM
#6
Thread Starter
Hyperactive Member
Re: fread/fwrite help
pfft...
now it works...
lol... i left it alone for 15 mins ... and come back to it... and it works... OoOo Scary. o.O
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 11th, 2005, 03:37 AM
#7
Thread Starter
Hyperactive Member
Re: fread/fwrite help
okay another Question...
NO STEALY IDEA.
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;
idk how to go about the deleting of the files. i tried unlink and unset.
as you can see i even chmod the file to 0777.
Once i get the basics down... ill be able to be more creative...
Last edited by PlaGuE; Nov 11th, 2005 at 03:40 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 11th, 2005, 04:09 AM
#8
Re: fread/fwrite help
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.
-
Nov 11th, 2005, 04:18 AM
#9
Thread Starter
Hyperactive Member
Re: fread/fwrite help
again... after i leave it alone... it fixes itself...
*** IS UP WITH THAT?.lol
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|