简体   繁体   中英

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

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

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';
})

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM