zeus-dev's avatar

Best way to store files in Laravel

Hello everyone (:

I'm having a project with laravel, and I need to upload some [sensitive files] using this application.

So I want to know what is the best way to store files in a private folder (not the public).

0 likes
7 replies
zeus-dev's avatar

@Resin01

Thanks for replying :)

Yeah I read the documentation of the Storage Service, it seems a bit clear, and I practiced a bit :P.

So what I did, is to create a new disk in the filesystems.php, because I want a folder not public, so I choose to create my storage folder in the storage/app/myFolder.

I uploaded successfully my file into the new driver using :

$request->file('myfirstFile')->storeAs('myFolder',$finalFile);

The file is uploaded, now I want to download it :

$file= Storage::disk('myDisk')->get($fileName);

the file is charged (I tried to debug it using dd() :P)

Now I want to know how I can download it please ):

zeus-dev's avatar

@Cronix @jlrdw

Thanks for replyig.

Actually working now with return Storage::disk('myDisk')->download($filename); and even return response()->download($pathToFile).

But when I want to pass more arguments to the reponse(), especially the headers; it gives me an error : The file "5b0ea5ec524b7.zip" does not exist !

return response()->download($fileName,$storagePath, $headers);

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

According to the docs, where you are using $storagePath, it should be the alternate name of the file, not an actual path. Like lets say the actual name of the file in storage is 5b0ea5ec524b7.zip, but you want the user to download it as '2018-05-30-report.zip`

return response()->download($pathToFile, $name, $headers);

1 like
jlrdw's avatar

@zeus-dev thanks, the There are docs? was just meant a good clean humor.

1 like

Please or to participate in this conversation.