awarren's avatar

Uploads going to /public instead of storage/app

I'm trying to handle file uploads using the example at https://laravel.com/docs/5.2/requests#files. I was expecting that when I did $file->move() it would go to storage/app but it's going to /public instead. Any ideas? Thanks.

0 likes
4 replies
usama.ashraf's avatar

@awarren you have to specify.

Input::file('image')->move(storage_path() . '/uploads-folder', $fileName);
Snapey's avatar

The example in the docs is $request->file('photo')->move($destinationPath);

So, what have you set destination path to?

awarren's avatar

The $destinationPath was documents/some_folder_name. It appears that Request->file() is a Symphony class that doesn't use the Laravel Filesystem drivers. Not sure where it's getting it's storage root but it's /storage.

If I use storage_path('app/documents') as the document root it works as expected and stores the files in storage/app/documents.

Here's what I wound up using:

// from config
// 'document_folder' => 'app/documents',

$baseFolder =  config('app.document_folder');
$subfolder = 'some_folder_name';
$destinationPath = "$baseFolder/$customFolder/";
$request->file('keyname')->move(storage_path($destinationPath), $sanitizedFilename);

Thanks everyone for your input.

awarren's avatar

In case anyone is wondering what I did to sanitize the custom folder and file names, I'm using this - https://gist.github.com/dhaupin/b109d3a8464239b7754a to generate something like this - app/documents/test_one_with_file_21/test1_with_a_realy_long_name_1.pdf where the filename is generated from test1 with a realy long name (1).pdf and the folder is generated from Test One With File plus a record id (for collision avoidance).

Here are a few more folder examples from Faker company names:

Kertzmann-Harber - app/documents/kertzmannharber_8  
Schumm Ltd - app/documents/schumm_ltd_15  
Gibson, Upton and Lemke - app/documents/gibson_upton_and_lemke_20  

Please or to participate in this conversation.