0

I am having some troubles with laravels filesystem uploading.

When I try to execute this code

Storage::disk('public')->put(
            $img->getClientOriginalName(),
            file_get_contents($img->getRealPath())
        );

nothing happens locally in the public folder, I even checked if the file exists and it returns true

dd(Storage::disk('public')->exists($img->getClientOriginalName()));

For now I am using the $img->move method and it works as I want to.

Disk is also configured in filesystems.php

 'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'visibility' => 'public',
        ],

I am confused with this because a couple of weeks ago it worked as it should on another project.

2
  • If you want to upload files in /public folder write 'root' => public_path('') Commented May 5, 2016 at 18:37
  • In your example, could you please show how you define $img Commented May 6, 2016 at 5:30

2 Answers 2

1

I have now fixed this problem with the help of Claudio by using 'root' => public_path('').

Sign up to request clarification or add additional context in comments.

Comments

0

This should work:

if ($request->hasFile('myFile'))
{
    $fileExtension = strtolower($request->file('myFile')->getClientOriginalExtension());
    $newFilename = str_random(20) . '.' . $fileExtension;
    $storagePath = storage_path() . '/app/uploads/';
    $request->file('myFile')->move($storagePath, $newFilename);
}

1 Comment

This is the solution am I using currently and it works fine, but I want to use the filesystems feature which doesn't actually store files on the local disk. The file does appear on the disk if I check for its existence or even if I get it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.