我可以在本地工作时上传图像,但是当我将网站移动到托管时,它不会在数据库中获取图像名称时上传图像,
我的filesystems.php
'default' => env('FILESYSTEM_DRIVER', 'local'),
disks' => [
'local' => [
'driver' => 'local',
'root' => public_path('images/'),
],
....
我的上传代码示例:
if ($request->hasFile('imageOne')) {
$imageOne = $request->file('imageOne');
$filename = 'productone' . '-' . time() . '.' . $imageOne->getClientOriginalExtension();
$location = public_path('images/');
$request->file('imageOne')->move($location, $filename);
$product->imageOne = $filename;
}
问题:
In host i get uploaded
image name in database
, but no image in mypublic/images
folder.
有什么想法吗?
更新
我在主机中发现了有趣的文件夹,因为我将所有 public
文件夹文件移动到服务器 public_html
现在它在我的根目录中创建了另一个名为 public< 的文件夹
里面有 images
文件夹,其中包括我迄今为止上传的所有图像!
问题:
- 为什么 laravel 在我的根目录中创建了新的
public/images
文件夹而不是 使用我的public_html
? - 如何解决?
最佳答案
已解决
我已将此代码添加到我的 public_html/index.php
文件中,现在可以使用了。
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
希望有帮助。
关于php - laravel 不上传图像到服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49290053/