An example for retrieving a file from the storage folder of Laravel. (Often you do not want files being saved in a public/upload folder for obvious reasons). For example, you would add this function to your routes.php, and when you get/3.png
the browser will download the file with filename of 3.png. Filenames should be unique, it’s also a good idea to keep the original filename in the database along with the new unique one that was created at upload.
public function get($filename){ $entry = Fileentry::where('filename', '=', $filename)->firstOrFail(); $file = Storage::disk('local')->get($entry->filename); $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); $filename = $storagePath . "/" . $entry->filename; header('Content-Type: application/octet-stream'); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"" . basename($entry->filename) . "\""); readfile ($filename); }