skip to Main Content

My structure is like this:

/laravelfiles
/public_html
--/demo
----/index.php (and other files inside public folder)

I have changed the index.php to access /laravelfiles, everything works fine.

My config filesystem:

'local' => [
    'driver' => 'local',
    'root' => public_path(),
],

'public' => [
    'driver' => 'local',
    'root' => public_path(),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
],

When I try to store a file:

Storage::disk('public')->put($folder.'/'.$file_name, $file_data);

It stores inside laravelfiles/public folder. Because it is separated the file is inaccessible.

What I want is to store the file inside the /public_html/demo folder (the same folder where index.php is).

How do I do that?

3

Answers


  1. You must bind and change the public path in application to public_html by adding this line of code in AppServiceProvider.php

    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {    
              // uncomment this after deployment to actual server
            $this->app->bind('path.public', function() {
                return base_path('public_html');
            });
    
        }
    
    }
    
    Login or Signup to reply.
  2. Try to use a third party storage, like Amazon S3 or Ms Azure. They have basic/free plans too.

    Login or Signup to reply.
  3. Try add in your config/filesystems.php

    'custom' => [
            'driver' => 'custom',
            'root'   => '../path/to/your/new/storage/folder',
        ],
    

    and then

    Storage::disk('custom')->put($folder.'/'.$file_name, $file_data);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search