(PHP 5 >= 5.1.2, PHP 7, PHP 8)
SplTempFileObject::__construct — Construir un nuevo objeto de fichero temporal
Construir un nuevo objeto de fichero temporal.
maxMemoryLa cantidad máxima de memoria (en bytes, por omisión es 2 MB) para el fichero temporal a usar. Su el fichero temporal supera este tamaño, Este será movido a un archivo en el directorio temporal del sistema.
Si maxMemory es negativo, se usará memoria.
Si maxMemory es cero, no se usará memoria.
Lanza una RuntimeException si un error ocurre.
Ejemplo #1 Ejemplo de SplTempFileObject()
Este ejemplo escribe un fichero temporal en la memoria mientras se puede escribir y leer en este.
<?php
$temp = new SplTempFileObject();
$temp->fwrite("Esta es la primera línea\n");
$temp->fwrite("Y esta es la segunda.\n");
echo "Escrito " . $temp->ftell() . " bytes al fichero temporal.\n\n";
// Rebobina y lee lo que fué escrito
$temp->rewind();
foreach ($temp as $line) {
echo $line;
}
?>Resultado del ejemplo anterior es similar a:
Escrito 47 bytes al fichero temporal. Esta es la primera línea Y esta es la segunda.
Noting that when the tmp file exceeds memory limitations and is written to the system temp directory, it is deleted upon completion of the script it was initially created in. At least that is what I have seen and wanted to document for others since it wasn't clear.