Reputation: 1640
im struggling with something simple as reading an image in ImageMagick and not sure why
The website is hosted under linux PHP version 5.4
After uploading the image i do this in order to print it.
$image = $_FILES['file']['name'];
$imagen = new Imagick($image);
$imagen->thumbnailImage(100, 0);
echo $image;
(pub1.gif) it's the name of the original image to be uploaded
But i'm getting the following error and no idea how to handle it.
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `pub1.gif': No such file or directory @ blob.c/OpenBlob/2480' in /home/content/38/10882038/html/carsventa/accountpass/post/publish-advertisement.php:74Stack trace:#0 /home/content/38/10882038/html/carsventa/accountpass/post/publish-advertisement.php(74): Imagick->__construct('pub1.gif')#1 {main} thrown in /home/content/38/10882038/html/carsventa/accountpass/post/publish-advertisement.php on line 74
Upvotes: 0
Views: 582
Reputation: 24439
The global $_FILES['file']['name']
is the original filename, not the file on disk. The uploaded image is in a temp file under $_FILES['file']['tmp_name']
, which will be deleted on script completion. See docs
$image = $_FILES['file']['tmp_name'];
$imagen = new Imagick($image);
$imagen->thumbnailImage(100, 0);
echo $image;
Upvotes: 2
Reputation:
You should be using:
$image = $_FILES['file']['tmp_name'];
instead of:
$image = $_FILES['file']['name'];
You're trying to use the client file, that is not located in your server, therefore the library cannot access it properly.
Upvotes: 2