PHP code example of lodev09 / php-upload
1. Go to this page and download the library: Download lodev09/php-upload library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lodev09 / php-upload example snippets
use \Upload\Upload;
if (isset($_FILES['files'])) {
$validations = array(
'category' => array('document', 'image', 'video'), // validate only those files within this list
'size' => 20 // maximum of 20mb
);
// create new instance
$upload = new Upload($_FILES['files'], $validations);
// for each file
foreach ($upload->files as $file) {
if ($file->validate()) {
// do your thing on this file ...
// ...
// say we don't allow audio files
if ($file->is('audio')) $error = 'Audio not allowed';
else {
// then get base64 encoded string to do something else ...
$filedata = $file->get_base64();
// or get the GPS info ...
$gps = $file->get_exif_gps();
// then we move it to 'path/to/my/uploads'
$result = $file->put('path/to/my/uploads');
$error = $result ? '' : 'Error moving file';
}
} else {
// oopps!
$error = $file->get_error();
}
echo $file->name.' - '.($error ? ' [FAILED] '.$error : ' Succeeded!');
echo '<br />';
}
}
term
$ composer