Laravel符号链接和cPanel

问题描述:

在Laravel网站上,我正在使用符号链接来存储和显示存储中的图像.

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

使用

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...

使用cPanels File Manager创建网站的副本并移至新位置后,公共目录中的存储符号链接已成为文件夹,而不是符号链接. 之后,当我尝试上传新的新闻文章时,我可以看到它是在主存储文件夹中上传的,而不是在公共/存储中,因此结果是图像不显示.那是因为它不再是一个符号链接,而现在是一个文件夹.

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.

我已经使用SSH从公用目录中删除了存储文件夹,我再次使用了该命令

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?

我正在使用Laravel 5.5

I'm using Laravel 5.5

  1. 您可以用另一种方法来解决它,以创建一个symlinkexample.php文件 进入您的公用文件夹,然后将文件路径运行到浏览器中.
  2. 然后,存储文件夹将被创建到公用文件夹中.资料夹路径 将是公共的/存储的,并已链接到您的公共文件夹.
  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.

symlinkexample.php的以下代码:

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