Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing files outside the Laravel 5 Root Folder

I am developing a laravel 5 project and storing image files using imagine. I would want to store my image files in a folder outside the project's root folder. I am stuck at the moment The external folder where image files are supposed to be stored, I want to make it accessible via a sub-domain something like http://cdn.example.com Looking towards your solutions.

like image 355
Silvabullet Avatar asked Jun 01 '15 14:06

Silvabullet


People also ask

How do I change the default storage folder in Laravel?

storage mapping. By default, Laravel populates this entry in Application. php – This is hard coded to a directory relative to your applications root directory. To change this, we can modify the storage path at runtime with a service provider.

What is default path for store file in Laravel?

By default, the public disk uses the local driver and stores its files in storage/app/public . To make these files accessible from the web, you should create a symbolic link from public/storage to storage/app/public .


2 Answers

The laravel documentation could give you a helping hand.

Otherwise you could go to config/filesystems.php and add your own custom storage path for both local and production:

return [

    'default' => 'custom',
    'cloud' => 's3',
    'disks' => [

        'local' => [
            'driver' => 'local',
            'root'   => storage_path().'/app',
        ],

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

        's3' => [
            'driver' => 's3',
            'key'    => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
        ],

        'rackspace' => [
            'driver'    => 'rackspace',
            'username'  => 'your-username',
            'key'       => 'your-key',
            'container' => 'your-container',
            'endpoint'  => 'https://identity.api.rackspacecloud.com/v2.0/',
            'region'    => 'IAD',
        ],

    ],
];
like image 123
MartinJH Avatar answered Nov 14 '22 14:11

MartinJH


get ur path name from base_path(); function, then from the string add your desired folder location. suppose ur

base_path() = '/home/user/user-folder/your-laravel-project-folder/'

So ur desired path should be like this

$path = '/home/user/user-folder/your-target-folder/'.$imageName;

make sure u have the writing and reading permission

like image 41
Noob Coder Avatar answered Nov 14 '22 14:11

Noob Coder