我storage_path用来保存图像,并将我的存储文件夹象征性地保存到public_html
php artisan storage:link
Run Code Online (Sandbox Code Playgroud)
在本地,一切正常,当我上载图像时,它将上载到存储文件夹中,并且其链接将出现在public文件夹中,但是由于我移至实时主机和生产模式,因此我的图像将上载到存储文件夹中,但我public_html/storage和我都没有我无法让他们进入我的前端。
/config/filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Run Code Online (Sandbox Code Playgroud)
.env
FILESYSTEM_DRIVER=public
Run Code Online (Sandbox Code Playgroud)
controller sample
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($image)->resize(1200, 600)->save($location);
if(!empty($page->image)){
Storage::delete('images/' . $page->image);
}
$page->image = $filename;
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
小智 21
I see that the question has been answered but I want to suggest another solution which i found to be easy.
Go to the route folder your-app-folder/routes/web.php and register a new route as follows
Route::get('/linkstorage', function () {
Artisan::call('storage:link');
});
Run Code Online (Sandbox Code Playgroud)
then go to your website www.example.com/linkstorage and it will take you to a blank page.
that's it. The storage folder will be create. I hope it helps someone.
Abd*_*awy 14
从公共删除文件夹存储并在 Cron 作业中运行此命令 [ 一次 ]
ln -s /home/public_html/storage/app/public/home/dev5/public_html/public/storage
Run Code Online (Sandbox Code Playgroud)
Ali*_*war 10
我知道这是一个旧线程,但我们可以通过 Config/filesystem.php 中的一些更改来更改它
代替
'links' => [
public_path('/storage') => storage_path('app/public'),
],
Run Code Online (Sandbox Code Playgroud)
和
'links' => [
base_path('/public_html/storage') => storage_path('app/public'),
],
Run Code Online (Sandbox Code Playgroud)
您可以检查这个存储库。我已经在其中实现了 https://github.com/ali-chaudhry/Laravel-7-Boilerplate-with-Spatie-uuid-Unishrp-filemanager-integeration
我为解决这个问题做了什么:
php artisan storage:link我刚遇到此问题,而这就是我解决该问题的方法,而无需通过SSH进入服务器或运行CronJob:
对于Laravel 5+(尚未通过较低版本进行测试)
您可以使用Artisan::call()路由/控制器内部的方法来执行工匠命令,而无需使用终端。
$exitCode = Artisan::call('storage:link', [] );
echo $exitCode; // 0 exit code for no errors.
Run Code Online (Sandbox Code Playgroud)
这个答案适用于那些仍然面临问题的人
步骤1
storage从文件夹中删除链接public。
第2步
授予storage文件夹权限
chmod -R 775 storage/
Run Code Online (Sandbox Code Playgroud)
步骤3
创建符号链接
php artisan storage:link
Run Code Online (Sandbox Code Playgroud)
感谢您的所有帮助,我尝试php artisan storage:link在我的服务器上运行,但发现我的服务器symlink出于安全原因已禁用。
因此,我更改了所有图像上传功能,将图像上传到我的public文件夹而不是storage文件夹中,现在一切正常。
通过 public_path 更改 storage_path 设置
'public' => [
'driver' => 'local',
'root' => public_path('app/public_html/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = public_path('app/public_html/images/' . $filename);
Image::make($image)->resize(1200, 600)->save($location);
if(!empty($page->image)){
Storage::delete('images/' . $page->image);
}
$page->image = $filename;
}
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,您可以尝试:
$path = base_path().'/../public_html/images';
Run Code Online (Sandbox Code Playgroud)