DirPath = $DirPath; $this->DirId = $DirId; $this->ParentId = $ParentId; $this->ScanDir($client,$AuthToken,$DirTitle); } public function ScanDir($client,$AuthToken,$DirTitle='') { if ($DirTitle) { $this->DirTitle = $DirTitle; } else { $this->DirTitle = basename($this->DirPath); } #echo "Dir: ".$this->DirPath." Title: ".$this->DirTitle."\n"; #foreach(new DirectoryIterator($this->DirPath) as $file) { # if (!$file->isDot()) { # # Test to see if there are any #} foreach(new DirectoryIterator($this->DirPath) as $file) { if (!$file->isDot()) { if ($file->isDir()) { $newdir = $file->getPathname(); $this->CreateSubDir($client,$newdir,$title); $SubDir = $this->$newdir; $SubDir->ScanDir($client,$AuthToken); } else { $this->Files[] = $file->getPathname(); if (!$this->Gallery) { $Title = "Photos"; $this->CreateGallery($client,$this->DirPath,$Title); } $this->UploadPhoto($client,$AuthToken,$this->$Title->UploadURL,$file->getPathname()); } } } } public function UploadPhoto($client,$AuthToken,$UploadURL,$DirPath) { # Check to see if it is a PhotoCD File $pathParts = pathinfo($DirPath); if (stristr($pathParts['extension'],'pcd')) { $filename = $pathParts['filename']; echo "Converting $DirPath PhotoCD to Large JPEG\n"; exec('convert -size 2048x2048 '.$DirPath.' /tmp/'.$filename.'.jpg'); $DirPath = "/tmp/".$filename.'.jpg'; echo "Temporary filename: $DirPath\n"; } #$imageInfo = getimagesize($DirPath); if (stristr($pathParts['extension'],'jpg')) { $base = 'http://www.zenfolio.com'.$UploadURL.'?'; $base.= 'filename='.basename($DirPath); $url = $base; $file_contents = file_get_contents($DirPath); echo "uploading data to this URL: $url\n"; $r = new HttpRequest($url, HttpRequest::METH_POST); $headers = array('User-Agent' => 'The Image Depot Uploader', 'Content-Type' => 'image/jpeg', 'Content-Length' => filesize($DirPath), 'X-Zenfolio-Token' => $AuthToken); $r->setHeaders($headers); $r->setBody($file_contents); try { $xml = ($r->send()->getBody()); } catch (HttpException $ex) { #$xml = $ex; } } if ($filename) exec ('rm /tmp/'.$filename.'.jpg'); } public function CreateGallery($client,$DirPath,$Title="Photos") { $this->Gallery[] = $Title; $this->$Title = new DirObj(); #GalleryObj(); $this->$DirPath->ParentId = $this->DirId; $args = array('groupId' => $this->DirId, 'type' => 'Gallery', 'updater' => array('Title' => $Title, 'Caption' => '')); $result = $client->CreatePhotoSet($args); $this->$Title->UploadURL = $result->CreatePhotoSetResult->UploadUrl; $this->$Title->DirId = $result->CreatePhotoSetResult->Id; } public function CreateSubdir($client,$DirPath,$Title) { $this->SubDirs[] = $DirPath; $this->$DirPath = new DirObj(); $this->$DirPath->ParentId = $this->DirId; $this->$DirPath->DirPath = $DirPath; $trans = array("_" => " ", "___" => " & ", "-" => "'"); $Title = strtr(basename($DirPath),$trans); $args = array('parentId' => $this->DirId, 'updater' => array('Title' => $Title, 'Caption' => '')); $result = $client->CreateGroup($args)->CreateGroupResult; $DirId = $result->Id; echo "Got this DirId: $DirId\n"; $this->$DirPath->DirId = $DirId; } } ?>