首页 > 解决方案 > 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;

}

标签: phpgoogle-drive-api

解决方案


推荐阅读