Amazon S3에 PDF를 업로드하는 코드는 다음과 같습니다. PDF의 첫 번째 페이지에서 이미지를 만들고 s3에 업로드하는 것뿐입니다.Amazon S3 PDF 업로드 및 표지 이미지 작성
//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>";
}
나는 누군가가 내가 잘못 여기에 내가 다음과 같은 오류 얻을로 일을하고 무엇을 말해 줄 수, 보안을위한 '버킷'내 실제 버킷 이름을 바꾸 있습니다
PHP Fatal error: Uncaught exception 'ImagickException' with message 'Unable to read the file: h' in /var/www/ams/pub-new-issue.php:45\nStack trace:\n#0 /var/www/ams/pub-new-issue.php(45): Imagick->__construct('h')\n#1 {main}\n thrown in /var/www/ams/pub-new-issue.php on line 45,
감사
당신이 여기 말했듯했지만 다음과 같은 오류가 발생했습니다 ** catch되지 않은 예외 '이미지'/var/www/ams/d4cf8f3e33c27055fcb3.jpg을 열 수 없습니다 '라는 메시지와 함께'ImagickException ' : @ 오류/blob.c/OpenBlob/2587 '/var/www/ams/pub-new-issue.php:54\nStack 추적 : \ n # 0 /var/www/ams/pub-new-issue.php(54) : Imagick-> writeimage ('d4cf8f3e33c2705 ...') \ n # 1 {main} \ n /var/www/ams/pub-new-issue.php 54 행에 ** ** –
'/ var/www/ams/d4cf8f3e33c27055fcb3이 있습니다. jpg가 존재합니까? 웹 서버 사용자가 액세스 할 수 있습니까? 어쨌든 그 길은 어디에서 오는거야? '$ s3file'은 코드별로 http : //bucket.s3.amazonaws.com/publications/ ...이어야합니다. – ceejayoz
/var/www/ams가이 응용 프로그램의 루트 폴더이므로 액세스 할 수 있다고 가정합니다. 나는 당신이 제안한대로 [0]을 떨어 뜨 렸습니다. 그래서 그것이 어디서 얻는 지 확신 할 수 없습니까? –