简体   繁体   English

PHP使用Imagik将上传的图像转换为pdf格式

[英]PHP using Imagik to convert uploaded image to pdf format

I have a basic php based file uploader script. 我有一个基本的基于php的文件上传器脚本。 What I am looking to do is after the file is uploaded if the file that was uploaded is an image mime type then convert it into a pdf 我要做的是在文件上传后,如果上传的文件是图像mime类型,然后将其转换为pdf

Attached is the code I am using. 附件是我正在使用的代码。 Also I have Imagemagick and Imagick module installed on my cpanel lunix based vps. 另外,我在基于cpanel lunix的vps上安装了Imagemagick和Imagick模块。

  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");
    }

My issue is when I try to upload a .jpg file it gets uploaded fine (so my php uploader script is working) however the above Imagick code does not seem to be working. 我的问题是,当我尝试上传.jpg文件时,它可以正常上传(因此我的php上传器脚本可以正常工作),但是上面的Imagick代码似乎无法正常工作。 I am calling it after the actual upload functionality of the script. 我在脚本的实际上传功能之后调用它。 Any suggestions? 有什么建议么?

嗯,好了,我从$ thefile中删除了文件扩展名,它现在正在工作,谢谢;)

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

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