1
Google 드라이브 파일 업로드 코드를 사용하고 있습니다. 다음 코드는 브라우저에서 올바르게 실행됩니다. 하지만 우리가 그것을하려고하면 우리는 오류 : fgets() 매개 변수 1 리소스, 주어진 문자열이 주어진다 나는 많은 해결책을 시도했지만 그것의 작동하지 않습니다. 웹 서비스에이 코드를 사용하여 파일을 Google 드라이브에 업로드하는 방법을 알려주세요.Google 드라이브에 파일 업로드 (PHP 웹 서비스 사용)
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
function uploadFile()
{
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('**********************');
$client->setClientSecret('*********');
$client->setRedirectUri('*********');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
if(!defined("STDIN")) define("STDIN", "fopen('php://stdin','r')");
$service = new Google_DriveService($client);
$authUrl = $client->createAuthUrl();
//Request authorization
print "Please visit:\n$authUrl\n\n";
print "Please enter the auth code:\n";
$authCode = trim(fgets(STDIN));
//$authCode = trim(file_get_contents(STDIN));
// Exchange authorization code for access token
$accessToken = $client->authenticate($authCode);
$client->setAccessToken($accessToken);
//Insert a file
$file = new Google_DriveFile();
$file->setTitle('Test document');
$file->setDescription('A test document');
$file->setMimeType('text/plain');
$data = file_get_contents('upload.txt');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'text/plain',
));
print_r($createdFile);
}
감사