Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Drive Api PHP多部分上传空内容_Php_File Upload_Google Drive Api - Fatal编程技术网

Google Drive Api PHP多部分上传空内容

Google Drive Api PHP多部分上传空内容,php,file-upload,google-drive-api,Php,File Upload,Google Drive Api,我的问题如下。 使用google drive api V3和php将文件上载到google drive时,上载的文件为空,文件大小为0字节。所有元数据上传都没有问题 session_start(); $file_tmp=$_SESSION['file_tmp']; $drive = new Google_Service_Drive($client); $data = file_get_contents($file_tmp); $file = new Google_Service_Dri

我的问题如下。 使用google drive api V3和php将文件上载到google drive时,上载的文件为空,文件大小为0字节。所有元数据上传都没有问题

session_start();
$file_tmp=$_SESSION['file_tmp'];
$drive = new Google_Service_Drive($client);

$data = file_get_contents($file_tmp);
    $file = new Google_Service_Drive_DriveFile(array(
      'data' => $data,
      'mimeType' => $file_type,
      'name' => $file_name,
      'description'=>$lolol,
      'uploadType' => 'multipart',
      'parents' => array($folderID),
      'uploadType' => 'multipart'
  ));
      $createdFile = $drive->files->create($file);
对于任何想知道的人来说,如果我回显$file_tmp,我会得到一个路径,比如/private/var/tmp/phpDpmi83。(我从一个带有输入类型file的html表单中得到这个)

最初我没有上传类型,其他论坛说这是问题所在,但我补充了这一点,仍然没有。
有什么建议吗

我相信你的目标如下

  • 您希望使用驱动器API将包含
    多部分/表单数据的文件上载到Google Drive中的特定文件夹
  • 您希望使用googleapis for PHP实现这一点
  • 在脚本中,
    $drive
    可用于上载文件
对于这个问题,这个答案如何

修改点:
  • 在脚本中,请将元数据和文件内容分开。由此看来,我认为你的剧本是可行的
当上述点反映到脚本中时,它将如下所示

修改脚本: 注:
  • 在此修改中,假定
    $data
    是文件内容。如果您的
    $file\u tmp
    无法使用,请使用示例文件进行测试
  • 在这种情况下,最大文件大小为5 MB。请小心这个
参考资料:

谢谢。我会试试这个并报告结果!
session_start();
$file_tmp=$_SESSION['file_tmp'];
$drive = new Google_Service_Drive($client);

$data = file_get_contents($file_tmp);

// I modified below script.
$file = new Google_Service_Drive_DriveFile(array(
    'mimeType' => $file_type,
    'name' => $file_name,
    'description'=>$lolol,
    'parents' => array($folderID),
));
$file_content = array(
    'data' => $data,
    'uploadType' => 'multipart'
);
$createdFile = $drive->files->create($file, $file_content);