Dev Doc
Dev Doc

Reputation: 170

Laravel application shared hosting, storage folder symbolic Link issue

I've created symbolic link at local PC, where its working fine, but I've uploaded same it to shared hosting, it is not working there. Basically I've images in the storage folder root/storage/public/images/

i want to display them by getting

$path=asset('storage/images/'.$item->image);

so the problem is in the shared hosting this way

$path=asset('storage/images/'.$item->image);

getting from the domain directory not from the parent directory, so for that there is no way to create symbolic link on shared hosting so what should I do to get images from the parent directory. I am beginner in laravel one can help me to solve this problem. Thanks

Upvotes: 5

Views: 6348

Answers (3)

Bilawal Awan
Bilawal Awan

Reputation: 432

I got this a solution here

first, delete the public/storage {storage} folder Second, put this code in the top of the web.php file

Artisan::call('storage:link');

this code runs the php artisan storage:link command manually

Upvotes: 3

marifyahya
marifyahya

Reputation: 51

first delete folder storage from folder public and, using this code in web.php

Route::get('foo', function(){
    $targetFolder = $_SERVER['DOCUMENT_ROOT'].'/project_foder/laravel/storage/app/public';
    $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/project_foder/public/storage';
    symlink($targetFolder, $linkFolder);
    return 'success';
});

or

Route::get('foo', function(){
    Artisan::call('storage:link', []);
    return 'success';
})

Upvotes: 5

Adil Ansari
Adil Ansari

Reputation: 356

Please create link folder with storage folder that will create same folder in the project file library. For further information, Symbolic links using PHP

Upvotes: 1

Related Questions