Upload – Subir y manipular archivos con PHP

1801

Upload es una libreria que permite simplificar la carga y validación de archivos. Cuando se envía un formulario, la libreria puede comprobar el tipo de archivo y el tamaño:

[php]

$storage = new \Upload\Storage\FileSystem(‘/path/to/directory’);
$file = new \Upload\File(‘foo’, $storage);

// Validate file upload
$file->addValidations(array(
// Ensure file is of type "image/png"
new \Upload\Validation\Mimetype(‘image/png’),

// Ensure file is no larger than 5M (use "B", "K", M", or "G")
new \Upload\Validation\Size(‘5M’)
));

// Try to upload file
try {
// Success!
$file->upload();
} catch (\Exception $e) {
// Fail!
$errors = $file->getErrors();
}

[/php]

Esto le ahorrará mucho tiempo y código tedioso.