Google Drive Api PHP多部分上传空内容
我的问题如下。 使用google drive api V3和php将文件上载到google drive时,上载的文件为空,文件大小为0字节。所有元数据上传都没有问题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
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);