简体   繁体   English

Image Magick将文件写入文件夹

[英]Image Magick writing file to folder

I'm trying to use Image Magick to write a file to a specific location, and use uniqid() to give a unique filename (as I expect many images to be uploaded). 我正在尝试使用Image Magick将文件写入特定位置,并使用uniqid()来提供唯一的文件名(因为我希望上传许多图像)。

Heres what I have so far: 以下是我到目前为止的情况:

$targetdir = '/var/www/html/uploads/';
$targetfile = basename($_FILES["image"]["name"]);

move_uploaded_file($targetfile,$targetdir);

$image = new Imagick($_FILES['image']['tmp_name']);
$uid = uniqid();

$image->setImageColorspace(imagick::COLORSPACE_RGB);
$image->setImageFormat("jpeg");
$image->scaleImage(80,80);
$image->setFilename($uid);

$_FILES['image']->writeImageFile($targetdir);

The file is originally a JPEG. 该文件最初是JPEG。

I am using Ubuntu 14.04 with nescessary delegates for the images. 我正在使用Ubuntu 14.04与图像的必要委托。

The error I am recieving is: 我收到的错误是:

 Call to a member function writeImageFile() on a non-object

Which is using the variable $targetdir - however according to php.net documentation writeImageFile should have a target directory to write the image. 哪个使用变量$ targetdir - 但是根据php.net文档,writeImageFile应该有一个目标目录来写入图像。

Thanks for your time 谢谢你的时间

Try calling 试着打电话

$image->writeImage($targetdir.$uid.".jpg"); 

instead of 代替

$_FILES['image']->writeImageFile($targetdir);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM