Page 1 of 1

Emptying data infile

Posted: Thu Aug 27, 2009 8:16 am
by jorgeng
I have read an infile and need now emptying the indata
in file, meaning write back an empty file, how do i do
that in php without deleting the file and allocate it again?

Anyone has a good php code for this?
:?

Re: Emptying data infile

Posted: Thu Aug 27, 2009 8:35 am
by Mark Baker

Code: Select all

 
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
rewind($fp);
fwrite($fp, '');
fclose($fp);
 

Re: Emptying data infile

Posted: Mon Aug 31, 2009 7:51 am
by jorgeng
Mark Baker wrote:

Code: Select all

 
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
rewind($fp);
fwrite($fp, '');
fclose($fp);
 
I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
:(

09:45 ORDER "sl) Omx Wampa - Stega till Sekvens 9A Kl.09.45 - Okrypterat OMXS309I" kurs 912.7500$<br>09:45 ORDER "sl) Omx Wampa - Stega till Sekvens 9A Kl.09.45 - Okrypterat OMXS309I" kurs 913.0000$<br>10:00 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS309I" kurs 910.0000$<br>11:03 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS309I" kurs 913.2500$<br>14:11 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS309I" kurs 907.2500$<br>14:11 ORDER "sl) Omx Wampa - Kurs Under Kl.11 Stapel Low - Eller Kl.17.20 OMXS309I" kurs 907.0000$<br>

Re: Emptying data infile

Posted: Mon Aug 31, 2009 9:23 am
by Mark Baker
jorgeng wrote:I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
The content of the file should be irrelevant.
If that doesn't work, try:

Code: Select all

 
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
ftruncate($fp, 0);
fclose($fp);
 

Re: Emptying data infile

Posted: Mon Aug 31, 2009 9:28 am
by jorgeng
Mark Baker wrote:
jorgeng wrote:I don't know but it doesn't work.
The file is a txt-file with html-characters, does this matters?
The content of the file should be irrelevant.
If that doesn't work, try:

Code: Select all

 
$fp = fopen($filename, 'r+');
$contents = fread($fp, filesize($filename));
ftruncate($fp, 0);
fclose($fp);
 
Yes, that worked.
Thanks
:wink: