I've created a Controller that backups table data in the form of SQL queries. On the browser, there are three checkboxes which contain 3 tables: order,posts and products. Moreover, when I select these tables, I want them to be stored in the directory storage/app like backup_on[Date-Time].sql and automatically be downloaded right from the browser.. When I clicked backup, I've got this error
file_put_contents(/home/vagrant/code/laravelBackup/storage/app/backup_on[2018-07-04 08:39:15].sql): failed to open stream: Protocol error
Thanks beforehand. This is my code:
public function download($output)
{
$time = Carbon::now()->toDateTimeString();
$file_name = 'backup_on[' . $time . '].sql';
// $file_name = 'database_backup_on_' . date('y-m-d') . '.sql';
// $file_name = 'backup.sql';
Storage::disk('local')->put($file_name, $output);
// Storage::lastModified($file_name);
$exists = Storage::disk('local')->exists($file_name);
if ($exists) {
// $name_of_file = 'backup';
$headers =
[
'Content-Description => File Transfer',
'Content-Type => application/octet-stream',
'Content-Disposition => attachment; filename=' . basename($file_name),
'Content-Transfer-Encoding => binary',
'Expires => 0',
ob_clean(),
flush(),
readfile($file_name),
unlink($file_name)
];
}
return Storage::download($file_name, $file_name, $headers);
}