
Hello everyone,
Sometimes when you take your laravel application from local to host (server) you might have issue with image/file(s) upload system in laravel and laravel instead of uploading your files to public_html
will upload them in root folder and will create new folder usually named public.
To solve this issue and you be able to upload your files where they meant to be you need to edit your index.php
under public folder and add these codes below into it.
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
now save the file and enjoy uploading files in your laravel app.
Update
In laravel 10 & 11 you can use following code in your bootstrap/app.php
file
->registered(function ($app) {
$app->usePublicPath(__DIR__.'/../../public_html');
})
withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})
->registered(function ($app) {
$app->usePublicPath(__DIR__.'/../../public_html');
})
->create();
- Last updated 9 months ago
Be the first to leave a comment.
You must login to leave a comment