php - PHP Google Drive Api - 回显在 if (!empty($_POST)) 块中不起作用
问题描述
我想将名为“文件”的文件夹中的文件上传到谷歌驱动器。它上传没有任何问题,但我想在单击提交按钮后将字符串回显到我的 html 文件。(我想打印生成的文件 ID。)但它不打印此代码块中的任何内容。请帮忙!
if (!empty($_POST)) {
$client->setAccessToken($_SESSION['accessToken']);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
foreach ($files as $file_name) {
$file_path = 'files/'.$file_name;
$mime_type = finfo_file($finfo, $file_path);
$file->setTitle($file_name);
$file->setDescription('This is a '.$mime_type.' document');
$file->setMimeType($mime_type);
$service->files->insert(
$file,
array(
'data' => file_get_contents($file_path),
'mimeType' => $mime_type
)
);
echo "file uploaded"; // This is not working!
}
finfo_close($finfo);
header('location:'.$url);exit;
}
解决方案
推荐阅读
- java - 使用 JSONObject 解析 JSON 时出现 IllegalAccessException
- python - 我应该怎么处理这个错误?/ 不支持的操作数类型:“str”和“str”
- javascript - Vue JSON 读写
- python - 为什么要多次插入元素?
- java - 如何加载保存到我的标记 ID 的图像并显示在该特定标记的自定义信息窗口中?
- scrapy - 如何从:使用带有 css 选择器的 Scrapy 获取 Href
- json - Json 身份验证请求正文包含美元符号
- javascript - “Javascript - 权威指南” - 未捕获的 TypeError:trace(...) 不是函数
- networking - 当系统没有连接任何东西时,单个 DNS 查询会发生什么?
- angular - 角材料
默认值选择来自