array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.ftruncate.php', 1 => 'ftruncate', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => 'Funciones del Sistema de Archivos', ), 'prev' => array ( 0 => 'function.ftell.php', 1 => 'ftell', ), 'next' => array ( 0 => 'function.fwrite.php', 1 => 'fwrite', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/filesystem/functions/ftruncate.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
ftruncate — Trunca un archivo a una longitud dada
Toma el puntero al archivo, handle
, y trunca el archivo a la
longitud size
.
handle
El puntero al archivo.
Nota:
handle
tiene que ser abierto para escritura.
size
El tamaño a truncar.
Nota:
Si
size
es mayor que el del archivo, éste se extiende con bytes null.Si
size
es menor que el del archivo, éste será truncado a ese tamaño.
Ejemplo #1 Ejemplo de truncar un archivo
<?php
$nombre_archivo = 'lorem_ipsum.txt';
$gestor = fopen($nombre_archivo, 'r+');
ftruncate($gestor, rand(1, filesize($nombre_archivo)));
rewind($gestor);
echo fread($gestor, filesize($nombre_archivo));
fclose($gestor);
?>
Nota:
El puntero al archivo no es cambiado.