Ad

Laravel Project Image Upload Error On Live Website But Successfully Works On Localhost

- 1 answer

If I try and edit the avatar in my profile from my localhost it works but on my website I get this error even though the code is exactly the same. This is is the log from error

[2019-02-04 06:32:18] laravel.ERROR: Image source not readable {"userId":1,"email":"[email protected]","exception":"[object] (Intervention\\Image\\Exception\\NotReadableException(code: 0): Image source not readable at /home/user/domains/mysite.com/blogv2/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:345)
[stacktrace]
#0 /home/user/domains/mysite.com/blogv2/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(64): Intervention\\Image\\AbstractDecoder->init('storage/avatar/...')
#1 /home/user/domains/mysite.com/blogv2/vendor/intervention/image/src/Intervention/Image/ImageManager.php(50): Intervention\\Image\\AbstractDriver->init('storage/avatar/...')
#2 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Intervention\\Image\\ImageManager->make('storage/avatar/...')
#3 /home/user/domains/mysite.com/blogv2/app/Http/Controllers/Api/UserController.php(105): Illuminate\\Support\\Facades\\Facade::__callStatic('make', Array)
#4 [internal function]: App\\Http\\Controllers\\Api\\UserController->cropAvatar(Object(Illuminate\\Http\\Request))
#5 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#6 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('cropAvatar', Array)
#7 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Api\\UserController), 'cropAvatar')
#8 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Route.php(169): Illuminate\\Routing\\Route->runController()
#9 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(659): Illuminate\\Routing\\Route->run()
#10 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#11 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#12 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#15 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#16 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#17 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#18 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 60, '1')
#19 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#20 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#21 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(661): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#22 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#23 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(602): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#24 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(591): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#25 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#26 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#27 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#28 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#31 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#32 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#33 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#34 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#37 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#40 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#41 /home/user/domains/mysite.com/blogv2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#42 /home/user/domains/mysite.com/public_html/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#43 {main}
"} 

I can update images manually in database but not through my live site. This is my upload manager

public function fileUpload(ImageRequest $request)
{
    $strategy = $request->get('strategy', 'images');

    if (!$request->hasFile('image')) {
        return $this->response->json([
            'success' => false,
            'error' => 'no file found.',
        ]);
    }

    $path = $strategy . '/' . date('Y') . '/' . date('m') . '/' . date('d');

    $result = $this->manager->store($request->file('image'), $path);

    return $this->response->json($result);
}
Ad

Answer

Thanks to one of the comments above and this post I found the solution. In case anyone ever finds this looking for an answer, my problem was that I created a sym link using

php artisan storage:link

but the link created had the wrong permissions and belonged to the wrong user group. After setting the correct permissions(775) I was able to set it to the correct user group by running this from my public folder.

sudo chown www-data:www-data storage 
Ad
source: stackoverflow.com
Ad