Beispiel #1
0
 */
function insertFile($service, $title, $description, $mimeType, $filename, $folderName, $folderDesc)
{
    $file = new Google_Service_Drive_DriveFile();
    $new_mime_type = 'application/vnd.google-apps.document';
    // Set the metadata
    $file->setTitle($title);
    $file->setDescription($description);
    $file->setMimeType($new_mime_type);
    // Setup the folder you want the file in, if it is wanted in a folder
    if (isset($folderName)) {
        if (!empty($folderName)) {
            $parent = new Google_Service_Drive_ParentReference();
            $parent->setId(getFolderExistsCreate($service, $folderName, $folderDesc));
            $file->setParents(array($parent));
        }
    }
    try {
        // Get the contents of the file uploaded
        $data = file_get_contents($filename);
        // Try to upload the file, you can add the parameters e.g. if you want to convert a .doc to editable google format, add 'convert' = 'true'
        $createdFile = $service->files->insert($file, array('data' => $data, 'mimeType' => $mimeType, 'uploadType' => 'multipart', 'convert' => 'true'));
        // Return a bunch of data including the link to the file we just uploaded
        return $createdFile;
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }
}
$permission_data = insertPermission($service, $driveInfo["id"], '*****@*****.**', 'anyone', 'reader');
echo "<br>Link to file: " . $driveInfo["alternateLink"];
header('location:' . $driveInfo["alternateLink"]);
Beispiel #2
0
 $gDirs = retrieveFiles($service, true);
 if (count($gDirs) == 0) {
     logMessage("No folders were found");
 } else {
     foreach ($gDirs as $dir) {
         if (!$gProjectDir && $dir->getTitle() == GDOC_REPORT_DIR_NAME) {
             $gProjectDir = $dir;
         }
     }
 }
 if (!$gProjectDir) {
     logMessage("Create GDrive folder '" . GDOC_REPORT_DIR_NAME);
     $gProjectDir = insertFolder($service, GDOC_REPORT_DIR_NAME);
 }
 logMessage("Set permissions for a report dir....");
 insertPermission($service, $gProjectDir->getId(), null, 'anyone', 'reader');
 $startTasksDate = getStartTasksDate();
 logMessage("Processing Asana tasks....");
 logMessage("Start from: " . $startTasksDate . "[" . DATETIME_TIMEZONE_ASANA . "]");
 $tasks = getAsanaTasks($startTasksDate);
 if (!is_array($tasks)) {
     logMessage("Something goes wrong during Asana request");
 } else {
     logMessage("Tasks found: " . $tasks['tasksCounter'] . ", projects found: " . $tasks['projectsCounter']);
     foreach ($templates as $template) {
         logMessage("Processing Report template '{$template}' ");
         reportMessage("<h1><strong>Reports:</strong></h1>");
         reportMessage("<h2><a href='http://" . BASE_SERVER . "/google-serverside.php'><strong>Make report drafts!</strong></a></h2>");
         foreach ($tasks['data'] as $clientName => $taskData) {
             //                var_dump($taskData);die;
             //                if (isset($taskData['project'])) {