1

I get the following error when trying to process uploaded images with imagick.

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `9eK59iu.jpg': No such file or directory @ error/blob.c/OpenBlob/2644' in D:\PATH\upload.php on line 77

The code looks like this:

<?php

    $new_folder_name = "D:/PATH/content";       
    mkdir("$new_folder_name",0700);

    $tmp_img = $_FILES["upload_file"]["tmp_name"];

    $img = new Imagick($tmp_img);
    $img->thumbnailImage(100 , 100 , TRUE);
    $img->writeImage($new_folder_name);

?>

Without imagick the image upload works just fine.

Only imagick won't open the image given to $_FILES

I also tried to open the image with imagick, after move_uploaded_file, like this:

<?php

    $extension = pathinfo($upload_file_name, PATHINFO_EXTENSION);
    $new_upload_file_name = rand(00000, 99999).".".$extension;

    $new_folder_name = "D:/PATH/content".time();        
    mkdir("$new_folder_name",0700);

    $path_to_file = $new_folder_name."/".$new_upload_file_name;

    move_uploaded_file($_FILES["upload_file"]["tmp_name"],$path_to_file);

    $img = new Imagick($path_to_file);
    $img->thumbnailImage(100 , 100 , TRUE);
    $img->writeImage($new_folder_name);

?>

neither works.. :-(

Any suggestion?

4

1 回答 1

1

阅读文件上传文档。PHP 分配的服务器端临时文件名,用于将上传的文件存储在['tmp_name']$_FILES 数组中。您正在尝试使用客户端 user-provided ['name'],它在您的服务器上的任何地方都不存在。

$tmp_img = $_FILES["upload_file"]["tmp_name"];
                                   ^^^^

您也只是假设上传成功。这不是一件好事。永远不要假设成功处理远程资源(Web API、文件上传、数据库操作等)。始终检查错误:

if ($_FILES['upload_file']['error'] !== UPLOAD_ERR_OK) {
  die("Upload failed with error code " . $_FILES['upload_file']['error']);
}
于 2013-06-02T02:34:50.420 回答