我正在使用storage_path
保存图片,并将我的存储文件夹符号化为public_html
php artisan storage:link
在本地,一切正常,当我上载图像时,它将上载到存储文件夹中,并且其链接将出现在
public
文件夹中,但是由于我移至实时主机和生产模式,因此我的图像将上载到存储文件夹中,但在public_html/storage
和我无法在前端使用它们。代号
/config/filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
.env
FILESYSTEM_DRIVER=public
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;
}
任何的想法?
最佳答案
我看到问题已得到解答,但我想提出另一种我认为很简单的解决方案。
转到路线文件夹your-app-folder/routes/web.php
并注册新路线,如下所示
Route::get('/linkstorage', function () {
Artisan::call('storage:link');
});
然后转到您的网站www.example.com/linkstorage
,它将带您进入空白页。而已。将创建存储文件夹。希望对您有所帮助。
关于php - Laravel存储链接不适用于生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50730143/