vedo che le persone hanno già risposto a questo, ma ho voluto aggiungere un po 'di contesto per coloro chi può avere un secchio protetto (richiede l'accesso). Nota, non è necessario generare gli URL se si parla direttamente al bucket S3, quindi è possibile utilizzare 'file_get_contents' ecc. Ma è molto più lento in quanto non è possibile utilizzare richieste di arricciatura multipla (per velocità). Comunque potresti usare pthreads se hai una versione php più recente.
INSTALLAZIONE: Installare il file di classe S3 per Amazon, ci sono modi semplici per aggiungerlo usando il compositore o semplicemente scaricando il file S3.php manualmente.
non assistiti: (vedi altri post su questo argomento, appena fondamentalmente utilizzare l'URL)
http(s)://<bucket>.s3.amazonaws.com/<object>
http(s)://s3.amazonaws.com/<bucket>/<object>
HTTPS sicuro (quando si protegge la benna):
https://amazon.com/file/you/wanted.xxx?ID:XXXXX?SIG:YYYYY
(1) Crea un https: // url e usa lo strumento multi curl per ottenerli tutti nello stesso momento (raccomandato).
Un esempio semplice:
$url = /path/to_the/file_name/file.ext
//note check amazon to confirm the path which will contain only "_" and no spaces.
$s3 = new S3($awsAccessKeyID, $awsSecretKey);
$curls[] = $s3->get_object_url($bucketName, $uri, '1 hour');
var_dump($results = multiCurlRequest($curls));
maggiori informazioni:
http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html#_getObjectUrl http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation
FYI:
function multiCurlRequest($curlList = array(),$user = '', $pass = '',$timeout = self::MULTI_REQ_TIMEOUT_SECS, $retTxfr = 1) {
if (empty($curlList) || count($curlList) == 0) return false;
$master = curl_multi_init();
$node_count = count($curlList);
for ($i = 0; $i < $node_count; $i++) {
$ch[$i] = curl_init($curlList[$i]);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, $timeout); // -- timeout after X seconds
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, $retTxfr);
curl_setopt($ch[$i], CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch[$i], CURLOPT_USERPWD, "{$user}:{$pass}");
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($master, $ch[$i]);
}
// -- get all requests at once, finish when done or timeout met --
do { curl_multi_exec($master, $running); }
while ($running > 0);
$results = array();
// -- get results from requests --
for ($i = 0; $i < $node_count; $i++) {
$results[$i] = curl_multi_getcontent($ch[$i]);
if ((int) curl_getinfo($ch[$i], CURLINFO_HTTP_CODE) > 399 || empty($results[$i])) {
$this->set_request( [ ['label' => '404', 'href' => $results[$i], '404' => '1' ] ]);
unset($results[$i]);
}
curl_multi_remove_handle($master, $ch[$i]);
curl_close($ch[$i]);
}
curl_multi_close($master);
if (empty($results)) return false;
//$results = array_values($results); // -- removed as we want the original positions
return $results;
}
possibile duplicato di [Come faccio a scaricare un file con PHP e il sdk Amazon S3?] (http: // stacko verflow.com/questions/7389394/how-do-i-download-a-file-with-php-and-the-amazon-s3-sdk) –