Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 211
Dev Doc Avatar asked Jun 14 '17 05:06

Dev Doc


3 Answers

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';
})
like image 114
marifyahya Avatar answered Nov 20 '22 16:11

marifyahya


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

like image 25
Bilawal Awan Avatar answered Nov 20 '22 15:11

Bilawal Awan


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

like image 1
Adil Ansari Avatar answered Nov 20 '22 15:11

Adil Ansari