我已经应用了文件插入代码,即将 csv 文件上传到谷歌驱动器。一切正常,但我得到的是重复的文件,而不是一次得到一个。我必须一次上传两个不同的文件,但我得到了 4 个文件,在这种情况下需要帮助
这是 google.php 文件,其中包含“Google_Client.php”、“Google_DriveService.php”和文件“insert.php”,用于插入包含函数 insertFile($service, $title, $description, $parentId , $mimeType, $文件名)
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
require 'insert.php';
session_start();
$title = 'Total Likes/Reblogs';
$description = 'Total Likes/Reblogs';
$title1 = 'Total Likes/Reblogs per post';
$description1 = 'Total Likes/Reblogs per post';
$parentId = '';
$mimeType = 'text/csv';
$filename = 'total.csv';
$fileNamePerPost = 'totalPerPost.csv';
$client = new Google_Client();
$client->setApplicationName("Google+ PHP Starter Application");
$service = new Google_DriveService($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken()) {
insertFile($service, $title, $description, $parentId, $mimeType, $filename);
insertFile($service, $title1, $description1, $parentId, $mimeType, $fileNamePerPost);
} else {
$state = mt_rand();
$client->setState($state);
echo $_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>