private function addVideoMeta(MOXMAN_Vfs_IFile $file, $metaData)
 {
     $fileName = $file->getName();
     $ext = strtolower(MOXMAN_Util_PathUtils::getExtension($fileName));
     if (preg_match('/^(mp4|ogv|webm)$/', $ext)) {
         $metaData->url_type = MOXMAN_Util_Mime::get($fileName);
         $name = substr($fileName, 0, strlen($fileName) - strlen($ext));
         // Alternative video formats
         $altExt = array("mp4", "ogv", "webm");
         foreach ($altExt as $altExt) {
             if ($ext != $altExt) {
                 $altFile = MOXMAN::getFile($file->getParent(), $name . $altExt);
                 if ($altFile->exists()) {
                     $metaData->alt_url = $altFile->getUrl();
                     break;
                 }
             }
         }
         // Alternative image format
         $altFile = MOXMAN::getFile($file->getParent(), $name . "jpg");
         if ($altFile->exists()) {
             $metaData->alt_img = $altFile->getUrl();
         }
     }
 }
示例#2
0
 /**
  * Returns the mime type of an path by resolving it agains a apache style "mime.types" file.
  *
  * @param string $path path to Map/get content type by
  * @param String $mimeFile Absolute filepath to mime.types style file.
  * @return String mime type of path or an empty string on failue.  
  */
 public static function get($path, $mimeFile = "")
 {
     $mime = "";
     $path = explode('.', $path);
     $ext = strtolower(array_pop($path));
     // Use cached mime type
     if (isset(self::$mimes[$ext])) {
         return self::$mimes[$ext];
     }
     // No mime type file specified
     if ($mimeFile === "") {
         $mimeFile = dirname(__FILE__) . '/mimes.txt';
     }
     // Open mime file and start parsing it
     if ($fp = fopen($mimeFile, "r")) {
         // Seek to last location
         if (self::$lastMimeFile === $mimeFile) {
             fseek($fp, self::$pos, SEEK_SET);
         }
         while (!feof($fp)) {
             $line = fgets($fp, 4096);
             $chunks = preg_split("/(\t+)|( +)/", $line);
             for ($i = 1, $l = count($chunks); $i < $l; $i++) {
                 // Cache mime types we do find
                 self::$mimes[$chunks[$i]] = $chunks[0];
                 if (rtrim($chunks[$i]) == $ext) {
                     // Store away file location
                     self::$pos = ftell($fp);
                     self::$lastMimeFile = $mimeFile;
                     // Return the mime type
                     $mime = $chunks[0];
                     break;
                 }
             }
         }
         fclose($fp);
     }
     return $mime;
 }
示例#3
0
 /**
  * Imports a local file to the file system, for example when users upload files.
  * Implementations of this method should also support directory recursive importing.
  *
  * @param String $localPath Absolute path to local file.
  */
 public function importFrom($localPath)
 {
     if (file_exists($localPath)) {
         $request = $this->getFileSystem()->createRequest(array("method" => "PUT", "path" => $this->getInternalPath(), "headers" => array("Content-Type" => MOXMAN_Util_Mime::get($this->getName()), "Content-Length" => filesize($localPath), "x-ms-blob-type" => "BlockBlob")));
         $request->setLocalFile($localPath);
         $body = $this->getFileSystem()->sendRequest($request)->getBody();
         if ($body) {
             throw new MOXMAN_Exception("Azure import failed.");
         }
     }
 }
示例#4
0
 /**
  * Sends the specified file to the client by streaming it.
  *
  * @param MOXMAN_Vfs_IFile $file File to stream to client.
  * @param Boolean $download State if the file should be downloaded or not by the client.
  */
 public function sendFile(MOXMAN_Vfs_IFile $file, $download = false)
 {
     // Check if the file is a local file is so use the faster method
     if ($file instanceof MOXMAN_Vfs_Local_File) {
         $this->sendLocalFile($file->getInternalPath(), $download);
         return;
     }
     // Check if the remote file system has a local temp path
     $localTempPath = MOXMAN::getFileSystemManager()->getLocalTempPath($file);
     if (file_exists($localTempPath)) {
         $this->sendLocalFile($localTempPath, $download);
         return;
     }
     if ($download) {
         $this->disableCache();
         $this->setHeader("Content-type", "application/octet-stream");
         $this->setHeader("Content-Disposition", "attachment; filename=\"" . $file->getName() . "\"");
     } else {
         $this->setHeader("Content-type", MOXMAN_Util_Mime::get($file->getName()));
     }
     // Non local file system then read and stream
     $stream = $file->open(MOXMAN_Vfs_IFileStream::READ);
     if ($stream) {
         // Read chunk by chunk and stream it
         while (($buff = $stream->read()) !== "") {
             $this->sendContent($buff);
         }
         $stream->close();
     }
 }
示例#5
0
 /**
  * Imports a local file into S3 by chunking the requests. This makes it possible to import
  * larger files.
  *
  * @param String $path Path on S3 where the file will be written.
  * @param String $localPath Local file system path to import from.
  */
 public function importFrom($localPath, $path)
 {
     $contentLength = filesize($localPath);
     $chunkSize = 8192 * 4;
     // S3 Minimum chunk length = 8192
     $numberOfChunks = ceil($contentLength / $chunkSize);
     $date = $this->getCurrentUtcDate();
     $emptyChunkMetaLength = strlen($this->getBodyChunk($this->hash(""))) - 1;
     // Excluding length byte
     $metaLength = $emptyChunkMetaLength + 1;
     if ($contentLength > $chunkSize) {
         $chunkMetaSize = $emptyChunkMetaLength + strlen(dechex($chunkSize));
         $lastChunkSize = $chunkSize - ($numberOfChunks * $chunkSize - $contentLength);
         $lastChunkMetaSize = $emptyChunkMetaLength + strlen(dechex($lastChunkSize));
         $metaLength += $chunkMetaSize * ($numberOfChunks - 1) + $lastChunkMetaSize;
     } else {
         $metaLength += $emptyChunkMetaLength + strlen(dechex($contentLength));
     }
     $request = $this->createRequest($path, "PUT");
     $request->setHeader("X-Amz-Content-SHA256", "STREAMING-AWS4-HMAC-SHA256-PAYLOAD");
     $request->setHeader("X-Amz-Date", $date->format("Ymd\\THis\\Z"));
     $request->setHeader("x-amz-decoded-content-length", $contentLength);
     $request->setHeader("content-encoding", "aws-chunked");
     $request->setHeader("content-length", $contentLength + $metaLength);
     $request->setHeader("x-amz-acl", $this->acl);
     $request->setHeader("Content-Type", MOXMAN_Util_Mime::get($path));
     if ($this->cacheControl) {
         $request->setHeader("Cache-Control", $this->cacheControl);
     }
     $canonical = $this->getCanonicalRequest($request, "STREAMING-AWS4-HMAC-SHA256-PAYLOAD");
     $signature = $this->getSignature($this->getStringToSign($canonical, $date), $date);
     $request->setHeader("Authorization", $this->getAuthorization($request, $date, $signature));
     $request->open();
     // Write contents in chunks
     $fp = fopen($localPath, "rb");
     if ($fp) {
         for ($i = 0; $i < $numberOfChunks; $i++) {
             $content = fread($fp, $chunkSize);
             $signature = $this->getSignature($this->getPayLoadStringToSign($signature, $date, $content), $date);
             $request->write($this->getBodyChunk($signature, $content));
         }
         fclose($fp);
     }
     // Write end chunk
     $signature = $this->getSignature($this->getPayLoadStringToSign($signature, $date), $date);
     $request->write($this->getBodyChunk($signature));
     $response = $request->close();
     $this->handleError($response);
 }