php - laravel 不上传图像到服务器上

标签 php laravel

我可以在本地工作时上传图像,但是当我将网站移动到托管时,它不会在数据库中获取图像名称时上传图像,

我的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 my public/images folder.

有什么想法吗?

更新

我在主机中发现了有趣的文件夹,因为我将所有 public 文件夹文件移动到服务器 public_html 现在它在我的根目录中创建了另一个名为 public< 的文件夹 里面有 images 文件夹,其中包括我迄今为止上传的所有图像!

问题:

  1. 为什么 laravel 在我的根目录中创建了新的 public/images 文件夹而不是 使用我的 public_html
  2. 如何解决?

最佳答案

已解决

我已将此代码添加到我的 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/

相关文章:

php - 如何使用 PHP 从底部剪切图像?

PHP MySQL : Redirecting Users ERROR

php - 调用未定义的方法 CodeIgniter\Database\MySQLi\Connection::like()

php - 随着我们的生产数据库的增长,如何测试查询是否花费了更长的时间?

javascript - 使用 window.axios 时 moxios 无法正常工作

laravel - 单击.. gmail(laravel)中的可疑链接错误

php - 摆脱日期codeigniter中的单引号

laravel - 更改 Nova 资源的资源 URL

php - 我在设置 laravel 时发生了什么错误

javascript - 未知的自定义元素 : <v-app> in Root when using vue with laravel