I am working on two things:
- Creating the CSV file using fopen() and inserting the data from mysql and Close the File.
- Now, need to upload that created file into AWS S3 bucket directly.
Now, I am able to created the CSV file, but unable to upload the file into AWS S3 bucket.
Laravel PHP Code:
public function download() {
$headers = array(
"Content-type" => "text/csv",
"Content-Disposition" => "attachment; filename=auditsystem.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0"
);
$columns = array(
'S.no',
'State Name',
'State Code'
);
$audit_params = DB::select(DB::raw("select * from table_state_codes"));
$callback = function() use ($audit_params, $columns) {
$file_name="auditsystem.csv";
$file = fopen('php://output', 'w+');
fputcsv($file, $columns);
foreach ($audit_params as $rowOrders) {
fputcsv($file, [
$rowOrders->id,
$rowOrders->state_name,
$rowOrders->state_code,
]);
}
fclose($file);
Storage::disk('s3')->put('uploads/' . $file_name, file_get_contents($file), 'public');
};
return response()->stream($callback, 200, $headers);
}
I am unable to Upload the File into AWS S3 bucket. Also, File format is kept w+, so that I can write as well as read also.
Please let me know where I am going wrong.Eagerly waiting for your opinions.
Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire