less than 1 minute read


지정된 폴더에 파일을 업로드 하는 방법 function insertFile($service, $title, $description, $parentId, $mimeType, $filename) {   $file = new Google_Service_Drive_DriveFile();   $file->setTitle($title);   $file->setDescription($description);   $file->setMimeType($mimeType);

  // Set the parent folder.   if ($parentId != null) {     $parent = new Google_Service_Drive_ParentReference();     $parent->setId($parentId);     $file->setParents(array($parent));   }

  try {     $data = file_get_contents($filename);

    $createdFile = $service->files->insert($file, array(       ‘data’ => $data,       ‘mimeType’ => $mimeType,   ‘uploadType’ => ‘multipart’,     ));

    // 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();   } }


/*  폴더 만들기 참고 File body = new File(); body.setTitle(“title”); body.setMimeType(“application/vnd.google-apps.folder”); File file = service.files().insert(body).execute(); */


🔗original-link

Updated: