user1012181 user1012181 - 4 years ago 366
PHP Question

mkdir(): Permission denied Laravel

I'm running the following script for an image upload in a server and getting the following error while it works perfectly on the localhost.

Code

$user_id = Auth::id();
$logicpath = 'userdp/' . $user_id . '/';
$pubpath = 'userdp/' . $user_id . '/' . $dpFile;
$path = '/userdp/' . $user_id . '/' . $dpFile;

if (!file_exists($logicpath)) {
mkdir($logicpath, 0777, true);
}


Error


ErrorException in UploadController.php line 605: mkdir(): Permission
denied

at HandleExceptions->handleError('2', 'mkdir(): Permission denied',
'/var/www/html/laravel/app/Http/Controllers/UploadController.php',
'605', array('dp' => object(UploadedFile), 'ext' => 'jpg', 'img' =>
object(Image), 'mime' => 'image/jpeg', 'width' => '200', 'height' =>
'200', 'fileSize' => '17152', 'dpFile' =>
'f12f298ab18d58a59c4ed8a589cd1cdc.jpg', 'user_id' => '1', 'logicpath'
=> 'userdp/1/', 'pubpath' => 'userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg', 'path' =>
'/userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg'))


I tried
chmod 777 public
and restarted the server. But it didn't work.

Answer Source

You have to perform chmod recursively to make sure all subdirectories also carry the same permissions. Try running this instead:

chmod -R 777 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download