首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >亚马逊S3上传PDF并创建封面图片

亚马逊S3上传PDF并创建封面图片
EN

Stack Overflow用户
提问于 2013-05-23 14:59:55
回答 1查看 1.9K关注 0票数 0

我有下面的代码,上传一个PDF到亚马逊S3,我需要做的是创建一个图像从第一页的PDF,并上传到s3以及。

代码语言:javascript
复制
//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致命错误:无法读取文件: h‘in /var/www/ams/pub-nStack trace:\n#0 /var/www/ams/pub-new-仙e.php( 45 ):Imagick-->_\n#1(’h‘)\n#1 {main}\n中抛入/var/www/ams/pub signe.php中的\n#1{main}\n,

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-23 15:02:58

代码语言:javascript
复制
$s3file='http://bucket.s3.amazonaws.com/publications/'.$finalName;
$im = new imagick($s3file[0]); 

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16717374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档