PHP code example of idealizetecnologia / class.upload.php
1. Go to this page and download the library: Download idealizetecnologia/class.upload.php 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/ */
idealizetecnologia / class.upload.php example snippets
use Verot\Uploader\Upload;
use Verot\Uploader\Exception\FileSizeInvalidException;
use Verot\Uploader\Exception\FileExtInvalidException;
...
$handle = new Upload($_FILES['image_field']);
if ($handle->uploaded) {
$handle->file_new_name_body = 'image_resized';
$handle->image_resize = true;
$handle->image_x = 100;
$handle->image_ratio_y = true;
try {
$handle->process('/home/user/files/');
echo 'image resized';
$handle->clean();
} catch (\Exception $e) {
// TODO: Catch exception when upload file
if ($e instanceof FileSizeInvalidException) {
// TODO: Error file size invalid
} elseif ($e instanceof FileExtInvalidException) {
// TODO: Error file extension invalid
}
// TODO: Error upload process
}
}
$handle = new Upload('/home/user/myfile.jpg');
$handle = new Upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);
$handle = new Upload('php:mycustomname.ext');
$handle = new Upload('data:'.$file_contents);
$handle = new Upload('base64:'.$base64_file_contents);
$handle = new Upload($_FILES['image_field'], 'fr_FR');
$handle = new Upload('/home/user/myfile.jpg', 'fr_FR');