0

我有以下代码将 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 致命错误:在 /var/www/ams/pub-new-issue.php:45\n堆栈跟踪:\n#0 /var/www/ 中带有消息“无法读取文件:h”的未捕获异常“ImagickException” ams/pub-new-issue.php(45): Imagick->__construct('h')\n#1 {main}\n 在第 45 行抛出 /var/www/ams/pub-new-issue.php ,

谢谢

4

1 回答 1

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

$s3file是一个字符串,但您正在访问其中的数组索引。结果,您获取了第一个字符h. 仅$s3file在您的 Imagick 实例化中使用,您应该没问题。

于 2013-05-23T15:02:58.000 回答