class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
Hello. I just cant resize any image with the upload.
public function uploadCover($file, $where, $forceX, $forceY) {
$result = new \stdClass();
$result->filename = "";
$result->pathAndFilename = "";
$result->fileExt = "";
$upload = new \upload($file, 'pt_BR');
if ($upload->uploaded) {
// Formatos Aceitos (Extensoes)
if (in_array($upload->file_src_name_ext, array('jpeg', 'jpg', 'pdf', 'png', 'gif', 'svg'))) {
// Formatos Aceitos (Mimetypes)
$upload->allowed = array(
'image/jpg',
'image/pjpeg', // JPG no IE7 e IE8
'image/jpeg', // JPG no Chrome, Safari, Opera e Firefox
'image/png',
'image/gif',
'application/x-zip-compressed',
'application/pdf', // PDF p/ IE8 e Mozilla e Chrome e Safari e Opera
'application/download',
'application/applefile'
);
$upload->file_auto_rename = false;
$upload->file_overwrite = true;
$upload->image_convert = 'png';
$upload->image_resize = true;
$upload->image_ratio_y = true;
$upload->image_x = $forceX;
$upload->image_y = $forceY;
$upload->process($where);
// Upload deu tudo certo?
if ($upload->processed) {
// Define resultado
$result->fileExt = $upload->file_src_name_ext;
$result->filename = $upload->file_dst_name;
$result->pathAndFilename = $where . $upload->file_dst_name;
// Permissao total no arquivo
@chmod($result->pathAndFilename, 0777);
$upload->clean();
} else {
throw new Exception($upload->error);
}
} else {
throw new Exception("Extenssão inválida");
}
} else {
throw new Exception($upload->error);
}
return $result;
}
The result of log is:
system information - class version : 0.35dev - operating system : Linux - PHP version : 7.2.12-1+0~20181112102304.11+stretch~1.gbp55f215 - GD version : GD not present - supported image types : none - open_basedir : no restriction - upload_max_filesize : 64M (67108864 bytes) - language : pt_BR source is an uploaded file - upload OK - file name OK determining MIME type - Checking MIME type with Fileinfo PECL extension MAGIC path will not be used MIME type detected as image/png; charset=binary by Fileinfo PECL extension - MIME validated as image/png source variables - You can use all these before calling process() file_src_name : alias ls=rm -rf.png file_src_name_body : alias ls=rm -rf file_src_name_ext : png file_src_pathname : /tmp/phpXNdcMi file_src_mime : image/png file_src_size : 1072774 (max= 67108864) file_src_error : 0 process file to /var/www/tooba/assets/images/lojas/thizer/ - file size OK - file mime OK : image/png - file name safe format - destination variables file_dst_path : /var/www/tooba/assets/images/lojas/thizer/ file_dst_name_body : alias-ls-rm-rf file_dst_name_ext : png - no auto_rename if same filename exists - destination file details file_dst_name : alias-ls-rm-rf.png file_dst_pathname : /var/www/tooba/assets/images/lojas/thizer/alias-ls-rm-rf.png - no overwrite checking - auto-rotate applies only to JPEG images - no image processing wanted - process OK cleanup - delete temp file /tmp/phpXNdcMiReply
The result of log is:
system information
- class version : 0.35dev
- operating system : Linux
- PHP version : 7.2.12-1+0~20181112102304.11+stretch~1.gbp55f215
- GD version : GD not present
- supported image types : none
- open_basedir : no restriction
- upload_max_filesize : 64M (67108864 bytes)
- language : pt_BR
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
MAGIC path will not be used
MIME type detected as image/png; charset=binary by Fileinfo PECL extension
- MIME validated as image/png
source variables
- You can use all these before calling process()
file_src_name : alias ls=rm -rf.png
file_src_name_body : alias ls=rm -rf
file_src_name_ext : png
file_src_pathname : /tmp/phpXNdcMi
file_src_mime : image/png
file_src_size : 1072774 (max= 67108864)
file_src_error : 0
process file to /var/www/tooba/assets/images/lojas/thizer/
- file size OK
- file mime OK : image/png
- file name safe format
- destination variables
file_dst_path : /var/www/tooba/assets/images/lojas/thizer/
file_dst_name_body : alias-ls-rm-rf
file_dst_name_ext : png
- no auto_rename if same filename exists
- destination file details
file_dst_name : alias-ls-rm-rf.png
file_dst_pathname : /var/www/tooba/assets/images/lojas/thizer/alias-ls-rm-rf.png
- no overwrite checking
- auto-rotate applies only to JPEG images
- no image processing wanted
- process OK
cleanup
- delete temp file /tmp/phpXNdcMi