omarsow94's avatar

Unable to write in the "public/images" directory on macbook

Hello, i'm trying to upload image but got issue about permissions.

public function postBook(Request $request)
    {
        
        $image = $request->file('cover');
        $new_name = rand() . '.' . $image->getClientOriginalExtension();
        $image->move(public_path('images'), $new_name);
        dd($new_name);
        return redirect('/admin/add-book-manually');
    }

And i have this following error

Unable to write in the "/Users/makeba/Documents/Others_Projects/beugue_lire/public/images" directory 

Thanks in advance

0 likes
25 replies
bugsysha's avatar

Nope, that would be bad idea. Write to storage folder and use storage:link artisan command to make it public.

bugsysha's avatar

What are the permissions for storage folder?

bugsysha's avatar

Then there is nothing left but to try 777 :D

Isn't there Laravel built in logic for file upload?

bugsysha's avatar

Post ls -la of whole Laravel project and public folder.

omarsow94's avatar

i did it, and there is the result @bugsysha

āžœ  beugue_lire git:(develop) āœ— ls -la
total 1432
drwxr-xr-x@  32 makeba  staff    1024 Dec  3 21:56 .
drwxr-xr-x   19 makeba  staff     608 Dec  3 21:56 ..
-rw-r--r--@   1 makeba  staff    8196 Dec  3 21:58 .DS_Store
-rw-r--r--    1 makeba  staff     220 Oct  6 22:46 .editorconfig
-rw-r--r--    1 makeba  staff     793 Nov 27 15:46 .env
-rw-r--r--    1 makeba  staff     835 Nov 27 15:41 .env-prod
-rw-r--r--    1 makeba  staff     793 Nov 25 23:10 .env.example
-rw-r--r--    1 makeba  staff     251 Oct 27 05:23 .eslintrc.js
drwxr-xr-x   14 makeba  staff     448 Dec  4 22:49 .git
-rw-r--r--    1 makeba  staff     111 Oct  6 22:46 .gitattributes
-rw-r--r--    1 makeba  staff     163 Oct  6 22:46 .gitignore
-rw-r--r--    1 makeba  staff     175 Nov 25 23:21 .htaccess
-rw-r--r--    1 makeba  staff     242 Oct  6 22:46 .styleci.yml
drwxr-xr-x   11 makeba  staff     352 Nov 20 23:20 app
-rw-r--r--    1 makeba  staff    1686 Oct  6 22:46 artisan
drwxr-xr-x    4 makeba  staff     128 Oct  6 22:46 bootstrap
-rw-r--r--    1 makeba  staff    1531 Oct 21 15:41 composer.json
-rw-r--r--    1 makeba  staff  177947 Oct 21 15:42 composer.lock
drwxr-xr-x   15 makeba  staff     480 Nov 27 16:07 config
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 database
drwxr-xr-x  756 makeba  staff   24192 Nov 12 15:55 node_modules
-rw-r--r--    1 makeba  staff  460304 Nov 12 15:55 package-lock.json
-rw-r--r--    1 makeba  staff    1365 Oct 27 05:22 package.json
-rw-r--r--    1 makeba  staff    1156 Oct  6 22:46 phpunit.xml
drwxr-xr-x   13 777     staff     416 Dec  3 21:56 public
drwxr-xr-x    7 makeba  staff     224 Oct 10 18:12 resources
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 routes
-rw-r--r--    1 makeba  staff     563 Oct  6 22:46 server.php
drwxr-xr-x    5 makeba  staff     160 Oct  6 22:46 storage
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 tests
drwxr-xr-x   42 makeba  staff    1344 Oct 21 15:42 vendor
-rw-r--r--    1 makeba  staff     905 Nov 28 09:53 webpack.mix.js
Snapey's avatar

do you have an images folder? what are its permissions?

bugsysha's avatar

You have wrong owner for public folder. Run chown -R makeba public.

Snapey's avatar

your public folder is owned by someone called 777 and the permissions are 755

you seem to have chown and chmod mixed up. Possibly the same for the images folder

bugsysha's avatar

And chmod -R 777 public for permissions. Or try with less like 775 or 755 after chown.

omarsow94's avatar

@bugsysha the result is

otal 1432
drwxr-xr-x@  32 makeba  staff    1024 Dec  3 21:56 .
drwxr-xr-x   19 makeba  staff     608 Dec  3 21:56 ..
-rw-r--r--@   1 makeba  staff    8196 Dec  3 21:58 .DS_Store
-rw-r--r--    1 makeba  staff     220 Oct  6 22:46 .editorconfig
-rw-r--r--    1 makeba  staff     793 Nov 27 15:46 .env
-rw-r--r--    1 makeba  staff     835 Nov 27 15:41 .env-prod
-rw-r--r--    1 makeba  staff     793 Nov 25 23:10 .env.example
-rw-r--r--    1 makeba  staff     251 Oct 27 05:23 .eslintrc.js
drwxr-xr-x   14 makeba  staff     448 Dec  4 23:16 .git
-rw-r--r--    1 makeba  staff     111 Oct  6 22:46 .gitattributes
-rw-r--r--    1 makeba  staff     163 Oct  6 22:46 .gitignore
-rw-r--r--    1 makeba  staff     175 Nov 25 23:21 .htaccess
-rw-r--r--    1 makeba  staff     242 Oct  6 22:46 .styleci.yml
drwxr-xr-x   11 makeba  staff     352 Nov 20 23:20 app
-rw-r--r--    1 makeba  staff    1686 Oct  6 22:46 artisan
drwxr-xr-x    4 makeba  staff     128 Oct  6 22:46 bootstrap
-rw-r--r--    1 makeba  staff    1531 Oct 21 15:41 composer.json
-rw-r--r--    1 makeba  staff  177947 Oct 21 15:42 composer.lock
drwxr-xr-x   15 makeba  staff     480 Nov 27 16:07 config
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 database
drwxr-xr-x  756 makeba  staff   24192 Nov 12 15:55 node_modules
-rw-r--r--    1 makeba  staff  460304 Nov 12 15:55 package-lock.json
-rw-r--r--    1 makeba  staff    1365 Oct 27 05:22 package.json
-rw-r--r--    1 makeba  staff    1156 Oct  6 22:46 phpunit.xml
drwxrwxrwx   13 777     staff     416 Dec  3 21:56 public
drwxr-xr-x    7 makeba  staff     224 Oct 10 18:12 resources
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 routes
-rw-r--r--    1 makeba  staff     563 Oct  6 22:46 server.php
drwxr-xr-x    5 makeba  staff     160 Oct  6 22:46 storage
drwxr-xr-x    6 makeba  staff     192 Oct  6 22:46 tests
drwxr-xr-x   42 makeba  staff    1344 Oct 21 15:42 vendor
-rw-r--r--    1 makeba  staff     905 Nov 28 09:53 webpack.mix.js
bugsysha's avatar

You haven't changed it. Do you have zoom maybe?

bugsysha's avatar
bugsysha
Best Answer
Level 61

Run chown -R makeba public.

1 like
Snapey's avatar

and the images folder?

Your public folder is still owned by 777

bugsysha's avatar

Yeah, you've probably missed it when we mentioned it above. Good luck šŸ™‚

Please or to participate in this conversation.