Amazon Elastic Beanstalk에서 호스팅되는 php를 사용하여 첫 번째 웹 응용 프로그램을 만들고 있는데, 어떻게해야 할 지 조금만 생각해 봅니다. 내 임무는 AWS S3 클라우드에서 최종 고객이 지정한 파일에 접근하여 압축 한 다음 최종 zip 파일에 대한 다운로드 링크를 제공하는 것입니다. 난 정확히 내가 뭘 하려는지 인스턴스를 찾을 주위에 사냥을 많이 했어,하지만 PHP로 내 경험이 특정 솔루션이 나를 위해 일할 수 있는지 결정에 hindince되었습니다.Amazon S3에서 php로 파일 압축 및 다운로드
나는이 질문과 응답 here을 발견했으며 일반적인 감각으로 php 및 zip 다운로드를 처리하는 것처럼 보였으므로이를 필자의 요구에 맞출 수있을 것이라고 생각했습니다. 아래는 내가 PHP에있는 것입니다 : 여기
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require "./aws.phar";
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'key' => getenv("AWS_ACCESS_KEY_ID"),
'secret' => getenv("AWS_SECRET_KEY")
));
echo "Starting zip test";
$client->registerStreamWrapper();
// make sure to send all headers first
// Content-Type is the most important one (probably)
//
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="file.zip"');
// use popen to execute a unix command pipeline
// and grab the stdout as a php stream
// (you can use proc_open instead if you need to
// control the input of the pipeline too)
//
$fp = popen('zip -r - s3://myBucket/test.txt s3://myBucket/img.png', 'r');
// pick a bufsize that makes you happy (8192 has been suggested).
$bufsize = 8192;
$buff = '';
while(!feof($fp)) {
$buff = fread($fp, $bufsize);
echo $buff;
}
pclose($fp);
그리고 것은 내가 전화를 사용하고 무엇을 : 나는 또한 시도했다
$(document).ready(function() {
$("#download_button").click(function() {
$.get("../php/ZipAndDownload.php", function(data){alert(data)});
return false;
});
});
:
$(document).ready(function() {
$("#download_button").click(function() {
$.ajax({
url:url,
type:"GET",
complete: function (response) {
$('#output').html(response.responseText);
},
error: function() {
$('#output').html('Bummer: there was an error!');
}
});
return false;
});
});
지금 때마다이 다운로드 버튼을 클릭하면, "Start zip test"의 메아리가 나타나고 다른 것은 없습니다. 오류가없고 zip 파일이 없습니다. 내가 알아야 할 것은 무엇인가? 또는 내가 분명히 잘못하고있는 것은 무엇인가?
도움과 조언을 미리 보내 주셔서 감사합니다.
편집 : 다음은 데릭의 조언을받은 후입니다. 이것은 여전히 큰 불쾌한 문자열을 생성합니다.
<?php
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="file.zip"');
require "./aws.phar";
use Aws\S3\S3Client;
$bucket = 'myBucket';
$client = S3Client::factory(array(
'key' => getenv('AWS_ACCESS_KEY_ID'),
'secret' => getenv('AWS_SECRET_KEY')
));
$result = $client->getObject(array(
'Bucket' => $bucket,
'Key' => 'test.txt',
'SaveAs' => '/tmp/test.txt'
));
$Uri = $result['Body']->getUri();
$fp = popen('zip -r - '.$Uri, 'r');
$bufsize = 8192;
$buff = '';
while(!feof($fp)) {
$buff = fread($fp, $bufsize);
echo $buff;
}
pclose($fp);
?>
당신은 외부 프로그램을 실행하고 있다는 것을 의미하는 popen을 사용하고 있습니다. 커맨드 라인 앱은 ** s3 : // etc ...이란 무엇을 의미하는지 전혀 모른다 ** ** no ** idea. 그들은 URL을 다루지 않습니다. 파일 시스템 경로를 처리합니다. Unix/Windows를 사용하는 중이라면 기껏해야 NFS 또는 UNC 경로를 사용할 수 있습니다. –