error in imagic librarie - php
i am trying to use the class Imagick in the vertigo serv
i have this form
<form action="thumb.php" method="post" enctype="multipart/form-data">
<p>
<label for="file">Select a file:</label>
<input type="file" name="userfile" id="file"> <br />
<button>Upload File</button>
<p>
</form>
and this php
<?php
error_reporting(-1);
$imagePath = $_FILES["userfile"];
$thumbnailWidth = 100;
$thumbnailHeight = 100;
$srgbPath = 'thumb/sRGB_v4_ICC_preference.icc';
$image = new Imagick($imagePath);
$width = $im开发者_如何学运维age->getImageWidth();
$height = $image->getImageHeight();
$srgb = file_get_contents($srgbPath);
$image->profileImage('icc', $srgb);
$image->stripImage();
$image->setImageColorspace(Imagick::COLORSPACE_SRGB);
$fitWidth = ($thumbnailWidth / $width) < ($thumbnailHeight / $height);
$image->thumbnailImage(
$fitWidth ? $thumbnailWidth : 0,
$fitWidth ? 0 : $thumbnailHeight
);
$imagePathParts = pathinfo($imagePath);
$thumbnailPath = "thumb/miniaturas/".
$imagePathParts['filename'].'_'.
$thumbnailWidth.'x'.$thumbnailHeight.'.jpg';
$image->setImageCompressionQuality(90);
$image->writeImage($thumbnailPath);
echo $image;
$image->clear();
$image->destroy();
?>
and i receive this error:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `C:\Users\fel\VertrigoServ\www\login\main_image.jpg': No such file or directory @ error/blob.c/OpenBlob/2587' in C:\Users\fel\VertrigoServ\www\login\thumb.php:12 Stack trace: #0 C:\Users\fel\VertrigoServ\www\login\thumb.php(12): Imagick->__construct(Array) #1 {main} thrown in C:\Users\fel\VertrigoServ\www\login\thumb.php on line 12
i am trying to open a image that is located in the desktop but the error seems to search in the localhost paste:
`C:\Users\fel\VertrigoServ\www\login\main_image.jpg':
any idea?
if i change this
$imagePath = $_FILES["userfile"];
to this
$imagePath = 'thumb/main.jpg';
all works fine
thanks
A core problem you have is the path for the uploaded file. $_FILES["userfile"];
doesn't give you the file path, it gives you an array of file details (see http://www.w3schools.com/PHP/php_file_upload.asp for more info).
Your image will be copied into the PHP temporary directory, and its location can be found using $imagePath = $_FILES['userfile']['tmp_name'];
.
PHP will look within the folder that your script is running from by default, which will be why its looking in C:\Users\fel\VertrigoServ\www\login
. This means you'll either need your "thumbs" directory (where you save the thumbnail) in that folder, or to give the path to the correct location in full.
The rest of the code looks alright on first glance :)
use:
$imagePath = $_FILES["userfile"]["tmp_name"];
w3Schools ref
the main $_FILES["userfile"]
is an array that hold all the file information.
精彩评论