-2
I searched a PHP image upload library to use in my application, I chose this one. https://dhavalkapil.com/image-uploader/
I implemented and it is working and the success of sending an image results in Boolean(true), the same as "Successfully sent image" in human terms. If there is an error what is returned is an "Exception Object" with all information related to the image, path, arguments and exceptions.
What I don’t know is to use this library return to treat the error in a user-friendly way. I know how to extract keys, array values, and to be friendly, I printed the error return inside <pre>
.
The upload code is as follows::
<?php
require ("../src/ImageUploader.php");
try
{
$imageUploader = new ImageUploader( dirname( __FILE__ ) . "/upload", "meu_salt_randomico");
$res = $imageUploader->upload($_FILES["my_image"], "meu_id");
var_dump($res);
}
catch (Exception $e)
{
var_dump($e);
}
?>
And the mistake I need to fix is this::
Exception Object
(
[message:protected] => Size limit exceeded
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => D:\xxxxxxxxxxxxxxx\ImageUploader.php
[line:protected] => 202
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => D:\xxxxxxxxxxxxxxx\ImageUploader.php
[line] => 239
[function] => checkFileSize
[class] => ImageUploader
[type] => ->
[args] => Array
(
[0] => Array
(
[name] => wallpapersden.com_k-nioh-2_3936x2215.jpg
[type] => image/jpeg
[tmp_name] => D:\xxxxxxxxxxxxxxx\tmp\php9DDD.tmp
[error] => 0
[size] => 1824428
)
)
)
[1] => Array
(
[file] => D:\xxxxxxxxxxxxxxx\ImageUploader.php
[line] => 316
[function] => securityChecks
[class] => ImageUploader
[type] => ->
[args] => Array
(
[0] => Array
(
[name] => wallpapersden.com_k-nioh-2_3936x2215.jpg
[type] => image/jpeg
[tmp_name] => D:\xxxxxxxxxxxxxxx\php9DDD.tmp
[error] => 0
[size] => 1824428
)
)
)
[2] => Array
(
[file] => D:\xxxxxxxxxxxxxxx\user-profile-photo-upload.php
[line] => 30
[function] => upload
[class] => ImageUploader
[type] => ->
[args] => Array
(
[0] => Array
(
[name] => wallpapersden.com_k-nioh-2_3936x2215.jpg
[type] => image/jpeg
[tmp_name] => D:\xxxxxxxxxxxxxxx\php9DDD.tmp
[error] => 0
[size] => 1824428
)
[1] => meu_id123123123123
)
)
)
[previous:Exception:private] =>
)
I tried to extract from the error the received values as if it were extendable by extracting values from an array, but it gives error, and I don’t know how to proceed with it. Any reference for study or guidance please?
Returned the error message and could handle the information, thank you!
– AngeloJ