我正在做两件事:
现在,我能够创建CSV文件,但是无法将文件上传到AWS S3存储桶中。
Laravel PHP代码:
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);
}
我无法将文件上传到AWS S3存储桶。另外,文件格式保持为w +,这样我既可以写又可以读。
请让我知道我要去哪里了,请耐心等待您的意见。
谢谢。