Php 致命错误:无法在imagick中创建临时文件?

Php 致命错误:无法在imagick中创建临时文件?,php,imagick,Php,Imagick,我在一个名为下载的文件夹中有一些PDF文件,我想在php中使用imagick生成jpg格式的缩略图,但由于无法创建临时文件而出现错误。 我得到的错误是: Fatal error: Uncaught exception 'ImagickException' with message 'unable to create temporary file `/home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/images/dow

我在一个名为下载的文件夹中有一些PDF文件,我想在php中使用imagick生成jpg格式的缩略图,但由于无法创建临时文件而出现错误。 我得到的错误是:

Fatal error: Uncaught exception 'ImagickException' with message 'unable to create temporary file `/home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/images/downloads/demoPDF.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/397' in /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php:14 Stack trace: #0 /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php(14): Imagick->__construct('/home/vrwebqbj/...') #1 {main} thrown in /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php on line 14
到目前为止,我试过:

<?php
error_reporting(1);
$source       = __DIR__."/images/downloads/demoPDF.pdf"; //Source PDF File
$target     = "myfile.jpg"; // Output File



/*function genPdfThumbnail($source, $target)
    {*/
        //$source = realpath($source);
        $target = dirname($source).DIRECTORY_SEPARATOR.$target;
        //echo $target;
        //echo __DIR__;
        $im     = new Imagick($source."[0]"); // 0-first page, 1-second page
        $im->setImageColorspace(255); // prevent image colors from inverting
        $im->setimageformat("jpeg");
        $im->thumbnailimage(160, 120); // width and height
        $im->writeimage($target);
        $im->clear();
        $im->destroy();
   // }
    //genPdfThumbnail('images/downloads/demoPDF.pdf','myfile.jpg');
?>
<img src="KyoritsuElectric/admin/images/downloads/myfile.jpg" />


更改您的
$target=“myfile.jpg”
$target=\uuuu DIR\uuu。“/some_writeable_folder/myfile.jpg”否,这不起作用。事实上,我对imagick很陌生,所以不知道它是如何工作的。您能看到错误并判断出问题所在吗?从错误中我看到它表明库无法创建临时文件,这就是为什么我建议您将
$target
更改为其他可写目录,更改为您所更改的目录?您是否已检查该文件夹是否具有写入权限?您不应该将其完全更改为
$target=\uuuu DIR\uuu。“/some_writeable_folder/myfile.jpg”
而不是
一些可写文件夹
应该是可写目录的路径相同的问题我将其更改为$target=DIR。“/images/downloads2/myfile.jpg”;//输出文件并将文件权限设置为0777
Imagick
正试图在您提到的
$target
文件夹中为其创建一些临时文件,您必须使
下载2
完全公开文件夹