Amazon S3上传PDF和创建封面图像


Amazon S3 Upload PDF and Create Cover Image

我有下面的代码,将PDF上传到Amazon S3,我需要做的是从PDF的第一页创建一个图像并将其上传到S3。

//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
//check whether a form was submitted
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    //retreive post variables
    $fileName = $_FILES['file']['name'];
    $fileTempName = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $extension=end(explode(".", $fileName));
    $rand = rand(1,100000000);
    $sha1 = sha1($rand);
    $md5 = md5($sha1);
    $fName = substr($md5, 0, 20);       
    $finalName = $fName.'.'.$extension;
    //create a new bucket
    $s3->putBucket("bucket", S3::ACL_PUBLIC_READ);
    //move the file
    if ($s3->putObjectFile($fileTempName, "bucket", 'publications/'.$finalName, S3::ACL_PUBLIC_READ)) {
        $s3file='http://bucket.s3.amazonaws.com/publications/'.$finalName;
        $aS3File = 'publications/'.$finalName;
        $im = new imagick($s3file[0]); 
        // convert to jpg 
        $im->setImageColorspace(255); 
        $im->setCompression(Imagick::COMPRESSION_JPEG); 
        $im->setCompressionQuality(75); 
        $im->setImageFormat('jpeg'); 
        //resize 
        $im->resizeImage(640, 877, imagick::FILTER_LANCZOS, 1);  
        //write image on server (line 54) 
        $s3->putObjectFile("","bucket", 'publications/'.$im->writeImage($fName.'.jpg'), S£::ACL_PUBLIC_READ);
    }else{
        echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
    }

为了安全,我用'bucket'代替了我的实际桶名,谁能告诉我我在这里做错了什么,因为我得到以下错误:

PHP致命错误:未捕获异常'ImagickException'与消息无法读取文件:h' in/var/www/ams/pub-new-issue.php: 45 ' nStack跟踪:' n # 0/var/www/ams/pub-new-issue.php (45): Imagick -> __construct (h) ' n # 1{main}'n在/var/www/ams/pub-new-issue.php第45行抛出,

谢谢

$s3file='http://bucket.s3.amazonaws.com/publications/'.$finalName;
$im = new imagick($s3file[0]); 

$s3file是一个字符串,但是你访问的是其中的数组索引。因此,您将获取第一个字符h。在你的Imagick实例化中只使用$s3file,你应该没问题。