我有下面的代码,上传一个PDF到亚马逊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致命错误:无法读取文件: 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,
谢谢
发布于 2013-05-23 15:02:58
$s3file='http://bucket.s3.amazonaws.com/publications/'.$finalName;
$im = new imagick($s3file[0]); $s3file是一个字符串,但您正在访问其中的数组索引。因此,您将获取第一个字符h。在Imagick实例化中只使用$s3file,您应该会没事的。
https://stackoverflow.com/questions/16717374
复制相似问题