★ wanayoo — archive 1999 http://uk.php.net/manual/fr/function.ftruncate.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<ftellfwrite>
view the version of this page
Last updated: Sun, 20 Apr 2003

ftruncate

(PHP 4 )

ftruncate -- Tronque un fichier.

Description

int 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 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 add a note

<ftellfwrite>
 Last updated: Sun, 20 Apr 2003
show source | credits | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: Kewlio.net Limited
Last updated: Fri Jun 13 21:10:32 2003 BST