Php Laravel 5.0:CSV使用fopen()创建,并使用存储上传到AWS S3存储桶上
我正在做两件事:Php Laravel 5.0:CSV使用fopen()创建,并使用存储上传到AWS S3存储桶上,php,mysql,amazon-s3,laravel-5,Php,Mysql,Amazon S3,Laravel 5,我正在做两件事: 使用fopen()创建CSV文件,插入mysql中的数据并关闭该文件 现在,需要将创建的文件直接上传到AWS S3 bucket中 现在,我可以创建CSV文件,但无法将该文件上载到AWS S3 bucket中 Laravel PHP代码: public function download() { $headers = array( "Content-type" => "text/csv",
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 bucket中。另外,文件格式保持为w+,这样我既可以读也可以写
请让我知道我错在哪里。急切地等待你的意见
提前谢谢