使用带有PHP的google驱动器api将文件上传到特定文件夹
发布时间:2020-12-13 18:01:05 所属栏目:PHP教程 来源:网络整理
导读:我正在使用谷歌驱动器api上传文件, 到目前为止这是我的代码 现在文件上传到我的root,我想更改到另一个文件夹的路径, ?php error_reporting(E_ALL); ini_set('display_errors',1); require_once 'google-api-php-client/src/Google_Client.php'; require_once
我正在使用谷歌驱动器api上传文件,
到目前为止这是我的代码 现在文件上传到我的root,我想更改到另一个文件夹的路径, <?php error_reporting(E_ALL); ini_set('display_errors',1); require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_DriveService.php'; $client = new Google_Client(); // Get your credentials from the APIs Console $client->setClientId('***'); $client->setClientSecret('***'); $client->setRedirectUri('http://***'); $client->setScopes(array('https://www.googleapis.com/auth/drive')); if(empty($_GET['code'])) { $client->authenticate(); } $myfile= "video.mp4"; $type='video/mp4'; $service = new Google_DriveService($client); // Exchange authorization code for access token $accessToken = $client->authenticate($_GET['code']); $client->setAccessToken($accessToken); //Insert a file $file = new Google_DriveFile(); $file->setTitle('filename.mp4'); $file->setDescription('A video'); $file->setMimeType($type); $data = file_get_contents($myfile); $createdFile = $service->files->insert($file,array( 'data' => $data,'mimeType' => $type,)); print_r($createdFile); echo "<br />"; 我试过stackoverflow的一些帖子
像这样设置父文件夹:
//Set the Parent Folder $parent = new Google_Service_Drive_ParentReference(); //previously Google_ParentReference $parent->setId('0B9mYBlahBlahBlah'); $file->setParents(array($parent)); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |