Check out the download method
How to automatically download a file of storage???
I have a file in my storage folder, how can i download that file automatically?? With just a click!!??
return response()->download($file, 'filename.pdf', ['Content-Type' => 'application/pdf']);
@realrandyallen look, inside my function i have:
Storage::put('a.cfg', $some->text);
return Storage::download('a.cfg');
Then in the browser inspector, when i go to the Network tab i get the response, i double-click it and then download the file. I dont know what to do!!!
https://laravel.com/docs/5.7/filesystem#retrieving-files
return Storage::download('file.jpg');
return Storage::download('file.jpg', $name, $headers);
@EDDIEPUIG - it is weird that you are trying to upload and download file at the same time.
@MICHAELNGUYEN547 - Yes, im begginer. Im trying to send some info to put in a file and download the file, with only one click of a button. Do you have any better way?
In Controller
use Storage;
public function fordownload(Request $request){
Storage::put('your_file_name', $request->info);
return Storage::download('your_file_name');
}
In Route
Route::post('download','YourController@fordownload')->name('down');
In Blade
<form action="{{route('down')}}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="info">Add Info</label>
<input type="text" name="info">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
you want like that?
@AMK - I have tried this, but im getting 419 error, unknown status
Try this bro.... I have been test it. It generate myfile.txt in public folder. pls check public folder.
public function fordownload(Request $request){
$fileName= "myfile.txt";
\File::put(public_path($fileName),$request->info);
return response()->download($filename);
}
Please or to participate in this conversation.