【发布时间】:2018-07-23 12:34:53
【问题描述】:
当我在本地工作时,我可以上传我的图片,但是当我将我的网站移动到主机时,它不会在数据库中获取图片名称时上传图片,
我的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;
}
问题:
在主机中我上传了
image name in database,但我的中没有图像public/images文件夹。
有什么想法吗?
更新
我在主机中发现了有趣的文件夹,因为我将所有 public 文件夹文件移动到服务器 public_html 现在它在我的根目录中创建了另一个文件夹 public 并且里面有 images 文件夹,包括我的所有图像目前已上传!
问题:
- 为什么 laravel 在我的根目录中创建了新的
public/images文件夹而不是 使用我的public_html? - 如何解决?
【问题讨论】:
-
确保您在上传文件夹中拥有正确的权限
-
@Ikong 是吗? ibb.co/iis4nx
-
是的,很好。但是你不应该使用 move() ,因为它只是在移动而不是上传,请参阅laravel.com/docs/5.6/filesystem#file-uploads 以获得正确的功能
-
@Ikong 我更新了我的问题,请检查一下
-
好像是目录问题,能不能也发布一下你的public/index.php?或者你可以在那里检查它是否定义了正确的目录