baseDir = $path; $this->sourceIterator = $this->filterIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $path, FI::SKIP_DOTS | FI::UNIX_PATHS | FI::FOLLOW_SYMLINKS ))); return $this; } /** * Set a glob expression that will match files to upload to Amazon S3 * * @param string $glob Glob expression * * @return self * @link http://www.php.net/manual/en/function.glob.php */ public function uploadFromGlob($glob) { $this->sourceIterator = $this->filterIterator( new \GlobIterator($glob, FI::SKIP_DOTS | FI::UNIX_PATHS | FI::FOLLOW_SYMLINKS) ); return $this; } /** * Set a canned ACL to apply to each uploaded object * * @param string $acl Canned ACL for each upload * * @return self */ public function setAcl($acl) { $this->acp = $acl; return $this; } /** * Set an Access Control Policy to apply to each uploaded object * * @param Acp $acp Access control policy * * @return self */ public function setAcp(Acp $acp) { $this->acp = $acp; return $this; } /** * Set the multipart upload size threshold. When the size of a file exceeds this value, the file will be uploaded * using a multipart upload. * * @param int $size Size threshold * * @return self */ public function setMultipartUploadSize($size) { $this->multipartUploadSize = $size; return $this; } protected function specificBuild() { $sync = new UploadSync(array( 'client' => $this->client, 'bucket' => $this->bucket, 'iterator' => $this->sourceIterator, 'source_converter' => $this->sourceConverter, 'target_converter' => $this->targetConverter, 'concurrency' => $this->concurrency, 'multipart_upload_size' => $this->multipartUploadSize, 'acl' => $this->acp )); return $sync; } protected function getTargetIterator() { return $this->createS3Iterator(); } protected function getDefaultSourceConverter() { return new KeyConverter($this->baseDir, $this->keyPrefix . $this->delimiter, $this->delimiter); } protected function getDefaultTargetConverter() { return new KeyConverter('s3://' . $this->bucket . '/', '', DIRECTORY_SEPARATOR); } protected function addDebugListener(AbstractSync $sync, $resource) { $sync->getEventDispatcher()->addListener(UploadSync::BEFORE_TRANSFER, function (Event $e) use ($resource) { $c = $e['command']; if ($c instanceof CommandInterface) { $uri = $c['Body']->getUri(); $size = $c['Body']->getSize(); fwrite($resource, "Uploading {$uri} -> {$c['Key']} ({$size} bytes)\n"); return; } // Multipart upload $body = $c->getSource(); $totalSize = $body->getSize(); $progress = 0; fwrite($resource, "Beginning multipart upload: " . $body->getUri() . ' -> '); fwrite($resource, $c->getState()->getFromId('Key') . " ({$totalSize} bytes)\n"); $c->getEventDispatcher()->addListener( AbstractTransfer::BEFORE_PART_UPLOAD, function ($e) use (&$progress, $totalSize, $resource) { $command = $e['command']; $size = $command['Body']->getContentLength(); $percentage = number_format(($progress / $totalSize) * 100, 2); fwrite($resource, "- Part {$command['PartNumber']} ({$size} bytes, {$percentage}%)\n"); $progress .= $size; } ); }); } }