PHP 7 Imagick writeimage()路径问题

I'm trying to create a simple thumbnail image and upload to server using imagick. The image is being selected via a form and I am able to get the thumb created via Imagick, however it is not saving to the right location.

When I use the below code, the image saves to the same directory as the page the code is on and includes the file path within the image name. For example "\images\myuploaded.jpg" as the file name.

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $errors = array();
    if(preg_match("!image!", $_FILES['image']['type'])){
        $image = $_FILES['image']['tmp_name'];
        $imagethumb = new Imagick("$image");
        $imagethumb->setImageFormat("jpg");
        $imagethumb->thumbnailImage(100, 0);
        $imgpath = "\images\\".$_FILES['image']['name'];
        $imagethumb->writeImage($imgpath);
        $_SESSION['message']=$image;
    }else{
        $errors['image'] = "You must select a .png, .jpg, or .gif images file.";
        $_SESSION['message']=$errors['image'];
    }

}

Thanks for any help.

_t

dongyongyin5339
dongyongyin5339 谢谢zerkms!改变images/nik-1.jpg的路径解决了这个问题。简单的道路而不是Imagick。
大约 2 年之前 回复
dongxixia6399
dongxixia6399 那是因为/images/nik-1.jpg是一条绝对的道路。你有在文件系统根目录下创建的图像吗?
大约 2 年之前 回复
dousonghs58612
dousonghs58612 好的。我应该如何指定我想要的目录的路径?我尝试使用“/images/name-of-image.jpg,但收到错误。”UncaughtImagickException:无法打开图像`/images/nik-1.jpg':没有这样的文件或目录@error/blob.c/OpenBlob/2705"
大约 2 年之前 回复
duanchi8836
duanchi8836 \在linux上没有特殊含义
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐