'Php AWS S3 download multiple files at a time through server cron job
I am trying to download multiple files at a time by using the following script. But it is only downloading only the very first file.
require 'vendor/autoload.php';
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;
// Initial configurations.
$region = '*****';
$bucket = '*****';
$keyname = '**************';
$secret = '**************';
$s3 = Aws\S3\S3Client::factory([
'credentials' => [
'key' => $keyname,
'secret' => $secret
],
'version' => 'latest',
'region' => $region
]);
$object_lists = [ 'Initial_Data.csv', 'Processed_Data.csv' ];
foreach( $object_lists as $object_list ) {
$object = $s3->getObject([
'Bucket' => $bucket,
'Key' => $object_list,
]);
header('Content-Description: File Transfer');
header('Content-Type: binary/octet-stream');
header('Content-Disposition: attachment; filename='.$object_list);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
//send file to browser for download.
echo $object["Body"];
}
How do I download both the files at once? Also can someone tell me is this a right way to download the files through server cron?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
