function insertFile($service, $title, $description, $parentId, $mimeType, $filename) { $file = new Google_DriveFile(); $file->setTitle($title); $file->setDescription($description); $file->setMimeType($mimeType); // Set the parent folder. if ($parentId != null) { $parent = new ParentReference(); $parent->setId($parentId); $file->setParents(array($parent)); } try { $data = file_get_contents($filename); $createdFile = $service->files->insert($file, array('data' => $data, 'mimeType' => $mimeType)); // Uncomment the following line to print the File ID // print 'File ID: %s' % $createdFile->getId(); return $createdFile; } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } }
/** * @param folder id $parentId */ public function setParentId($parentId) { $parent = new ParentReference(); $parent->setId($parentId); $this->setParents(array($parent)); }