我正在使用带laragon的laravel,一切正常,当我上传图片时他们返回404
,public/storage
为空,但storage/app/public
有文件,{{1}有文件,所以它在公共文件夹中创建了一个错误的文件夹public,我确实运行了public/public
,因为我说它创建了我可以在我的编辑器中看到它的存储链接,但文件转到{ {1}}而不是php artisan storage:link command
,我怎样才能让它发挥作用?我想这是laragon的问题,因为它适用于其他环境,我也用“命名”url运行我的网站:myproject.test,我使用apache2作为网络服务器,请帮助修复它
答案 0 :(得分:0)
如果您使用的是Linux,则可以使用
ln -s [source] [virtual]
创建虚拟链接。在Windows上,您可以使用
mklink /j [virtual] [source]
做同样的事情。
请注意,您可能需要使用完整路径来创建链接。我在laragon上使用这个方法,它的工作原理。如果它们转到所需的文件夹,请在创建符号链接后双击链接检查它是否有效。如果没有,配置有问题。
<强>加成强>
我创建了一个控制台命令来自动化事物,也许你可以使用它:
用法:php artisan install:symlink
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class installSymlink extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:symlink';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This artisan command installs pinpacker symlinks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$links = ["./public/thumbnails","./public/resized"];
$folders = ["./storage/app/public/thumbnails/","./storage/app/public/resized/"];
chdir(base_path());
try {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($links as $i => $link){
$command = 'mklink /j "' . str_replace('/', '\\', $link) . '" "' . str_replace('/', '\\', $folders[$i]) . '"';
echo $command."\n";
exec($command);
}
} else {
foreach($links as $i => $link){
$command = 'ln -s ' . realpath($folders[$i]) . ' ' . $link;
echo $command ."\n";
exec($command);
}
}
printf("Symlinks created.\n");
} catch (Exception $e) {
printf($e->getMessage());
print_r($e);
}
}
}