Silvabullet
Silvabullet

Reputation: 93

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.

Upvotes: 9

Views: 20832

Answers (3)

Ioannis Chrysochos
Ioannis Chrysochos

Reputation: 438

You can move all or a part of storage folder in any folder of yours in your server. You must put a link from old to new folder.

ln -s new_fodler_path  older_folder_path

You can make a new virtual host to serve the new folder path.

Upvotes: -1

Noob Coder
Noob Coder

Reputation: 2896

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

Upvotes: 2

MartinJH
MartinJH

Reputation: 2609

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',
        ],

    ],
];

Upvotes: 9

Related Questions