php - 上传 PDF 问题

标签 php laravel upload

我正在构建一个基于 HelloSign API 的应用程序,为此我们需要将 PDF 上传到 HelloSign 以用作模板,但是我遇到的问题是我还需要在我们端存储 PDF 的副本,我已经写了代码但是不起作用。我在 null 上收到对成员函数 store() 的错误调用

我已经对此进行了一些谷歌搜索以及如何编写它,问题是我们已经使用 pdf 设置模板,但也想存储该文件

public function store(Request $request)
    {
        $this->template->setClientId(config('hellosign.client_id'));
        $this->template->addFile($request->file('pdf'));

        // here we upload the raw pdf to the database

        $path = $request->file->store('pdf');
        // create the upload and store the url
        $fileData = new Upload;
        $fileData->user_id = 1;
        $fileData->name = $request->file->getClientOriginalName();
        $fileData->path = $path;
        $fileData->timestamps = now();
        $fileData->save();
        /**/

预期的结果是,当上传将文件上传到服务器时,实际结果是在 $path = $request->file- 行上收到错误“Call to a member function store() on null” >商店('pdf');

这里是 $request->file('pdf') 的转储

#convertedFiles: array:1 [▼
    "pdf" => UploadedFile {#468 ▼
      -test: false
      -originalName: "User Setup From.pdf"
      -mimeType: "application/pdf"
      -error: 0
      #hashName: null
      path: "/tmp"
      filename: "phpmTqOhb"
      basename: "phpmTqOhb"
      pathname: "/tmp/phpmTqOhb"
      extension: ""
      realPath: "/tmp/phpmTqOhb"
      aTime: 2019-09-25 14:34:22
      mTime: 2019-09-25 14:34:22
      cTime: 2019-09-25 14:34:22
      inode: 398565
      size: 567747
      perms: 0100600
      owner: 1000
      group: 1000
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
    }
  ]

最佳答案

该字段的名称似乎是pdf

你想要

$path = $request->pdf->store('pdf');

关于php - 上传 PDF 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58100219/

相关文章:

php - 如何清除Laravel中的缓存?

javascript - 在 WordPress 的 javascript 中留下 API key 等私有(private)信息是否安全?

laravel - 如何在 laravel 中获取所有公共(public)路由

php - Route::model 在 Laravel 中是什么意思?

ruby-on-rails - 上传/下载文件 - Ruby On Rails 系统

php - MYSQL php数据库插入包括图像上传

php - 如何将它从 PHP 转换为 JavaScript?

php - 为什么 R::Store 不返回任何东西并在 redbeanphp 中崩溃?

database - 如果 DB::transaction 抛出错误,Laravel 5.3 没有回滚?

post - PUT 与 POST 上传文件 - 使用 Zend Framework 构建 RESTful API