2014-06-05 134 views
0

我有一個基於PHP的基本文件上傳腳本。我想要做的是在文件上傳後,如果上傳的文件是圖像MIME類型,然後將其轉換爲pdfPHP使用Imagik將上傳的圖像轉換爲pdf格式

附加是我使用的代碼。另外我的Imagemagick和Imagick模塊安裝在我的基於cpanel lunix的vps上。

if($thefileext =='jpg' || $thefileext =='png' || $thefileext =='jpeg') 
    { 
     echo "the filename is $thefile"; //echoing to make sure if statement works 
     $img = new Imagick("img/$thefile"); 
     $img->setImageFormat('pdf'); 
     $success = $img->writeImage("img/$thefile"); 
    } 

我的問題是,當我試圖把它上傳被上傳罰款.jpg文件(所以我的PHP上傳腳本工作),但是上面的Imagick代碼似乎並不奏效。我在腳本的實際上傳功能之後調用它。有什麼建議麼?

+1

'$ thefile'是否包含擴展名? Imagik默認爲指定文件名的文件擴展名,所以你可能只是用一個新的jpg來寫你的jpg。 http://www.php.net/manual/en/imagick.writeimage.php#refsect1-imagick.writeimage-parameters – cpilko

回答

0

啊好吧我刪除了文件擴展出$文件,它現在正在工作謝謝;)

相關問題