|
|
 |
ftruncate (PHP 4 ) ftruncate -- Tronque un fichier. Descriptionint ftruncate ( int fp, int size)
ftruncate() prend le pointeur de fichier
fp et le tronque à la taille de
size.ftruncate() retourne
TRUE en cas de succès, et
FALSE sinon.
User Contributed Notes ftruncate |
add a note |
d0hb0y at lynq dot com
29-Aug-2000 09:14 |
|
I've tested this function and it appears to work correctly with 4.0.1pl2
when a file is open in 'w' mode. Here's my sample code using rewind and
ftruncate on a file i've opened and
locked.
$handle=fopen($filename,"w") or
die();
$canwrite = flock($handle,LOCK_EX + LOCK_NB);
if
($canwrite) {
fputs($handle,"test data xxxxxxx");
rewind($handle); /* Rewind to the top */
fputs($handle,"test");
ftruncate($handle,ftell($handle));
/* Truncate to the current position */
}
fclose($handle);
//
output file will contain "test" only.
|
|
jim dot hatfield at insignia dot com
15-Jun-2001 12:58 |
|
ftruncate does not alter the position of the file pointer. If you edit a
file in-place by opening for reading and writing, reading the file,
truncating and writing out again, you have to seek to the beginning before
writing or you get as many NULLs as there were bytes in the original file,
then your new content.
|
|
add a note |
| |