Laravel symlink and cPanel

微笑、不失礼 提交于 2019-12-11 04:29:25

问题


On my Laravel website I'm using symlink to store and show the images from storage.

With

php artisan storage:link

I had created the symlink and everytime when I upload a new news article, the image is uploaded in the main Storage and with symlink it's setup to the public folder and I'm displaying the image properly.

So far so good, but when I've created a copy of the website, a problem appears...

When I've created a copy of the website with cPanels File Manager, and move to a new location, the storage symlink in the public directory has become a folder, not a symlink. After that when I try to upload a new news article, I can see it's uploaded in the main Storage folder, but not in the public/storage, so as a result the image is not displaying. That's because it's not a symlink anymore, but now it's a folder.

I've deleted the storage folder from the public directory, with SSH I've used the command again

php artisan storage:link

and I've created a new news article and the image is displaying properly, but now all other images are gone.

Is there any command that will regenerate the paths, so all other images will be display again?

I'm using Laravel 5.5


回答1:


  1. You can solve it in another way to create a symlinkexample.php file into your public folder and run the file path into browser.
  2. Then Storage folder will be created into public folder. Folder path will be public/storage with linked to your public folder.

Code below for symlinkexample.php :

<?php
    $targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
    $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
    symlink($targetFolder,$linkFolder);
    echo 'Symlink process successfully completed';
?>



回答2:


Try this:

In route/web.php add the following code:

Route::get('/storage', function(){
    \Artisan::call('storage:link');
    return "Se han vinculado las imágenes";
});


来源:https://stackoverflow.com/questions/51210036/laravel-symlink-and-cpanel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!