Esempio n. 1
0
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     $this->fileSystem->getCache()->remove($dest->getPath());
     $fromStream = $this->open("rb");
     $toStream = $dest->open("wb");
     while (($buff = $fromStream->read(8192)) !== "") {
         $toStream->write($buff);
     }
     $fromStream->close();
     $toStream->close();
 }
Esempio n. 2
0
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->isDirectory()) {
         $dest->mkdir();
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }
Esempio n. 3
0
 /** @ignore */
 private static function getPngInfo(MOXMAN_Vfs_IFile $file)
 {
     $stream = null;
     $info = array();
     try {
         $stream = $file->open(MOXMAN_Vfs_IFileStream::READ);
         $magic = $stream->read(8);
         if ($magic === "‰PNG\r\n\n") {
             // Is PNG
             // Read chunks
             do {
                 $buff = $stream->read(4);
                 if (strlen($buff) != 4) {
                     break;
                 }
                 $chunk = unpack('Nlen', $buff);
                 $chunk['type'] = $stream->read(4);
                 if (strlen($chunk['type']) != 4) {
                     break;
                 }
                 // Found header then read it
                 if ($chunk['type'] == 'IHDR') {
                     $header = unpack('Nwidth/Nheight/Cbits/Ctype/Ccompression/Cfilter/Cinterlace', $stream->read(13));
                     break;
                 }
                 // Jump to next chunk and skip CRC
                 $stream->skip($chunk['len'] + 4);
             } while ($buff !== null);
             $info = array("width" => $header["width"], "height" => $header["height"], "depth" => $header['type'] == 3 ? 8 : 32);
         }
         $stream->close();
         return $info;
     } catch (Exception $e) {
         if ($stream) {
             $stream->close();
         }
         throw $e;
     }
 }
Esempio n. 4
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MCE_File $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->exists() && $this->isDirectory()) {
         if (!$this->isFileOrEmptyDir()) {
             throw new MOXMAN_Exception("Copy non empty folders not supported by Azure.");
         } else {
             $dest->mkdir();
             return;
         }
     }
     if ($dest instanceof MOXMAN_Azure_File) {
         $containerUrl = MOXMAN_Util_PathUtils::combine($this->fileSystem->getContainerOption("account"), $this->fileSystem->getContainerOption("name"));
         $fromUrl = "/" . MOXMAN_Util_PathUtils::combine($containerUrl, $this->getInternalPath());
         $request = $this->getFileSystem()->createRequest(array("method" => "PUT", "path" => $dest->getInternalPath(), "headers" => array("x-ms-copy-source" => $fromUrl, "Content-Length" => 0)));
         $this->getFileSystem()->sendRequest($request);
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }
Esempio n. 5
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MOXMAN_Vfs_IFile $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if (!$this->exists()) {
         throw new Exception("Source file doesn't exist: " . $dest->getPublicPath());
     }
     if (MOXMAN_Util_PathUtils::isChildOf($dest->getPath(), $this->getPath())) {
         throw new Exception("You can't copy the file into it self.");
     }
     // File copy or dir copy
     if ($this->isFile()) {
         if ($dest instanceof MOXMAN_Vfs_Local_File) {
             copy($this->internalPath, $this->fromUtf($dest->getPath()));
         } else {
             // Copy between file systems
             $in = $this->open(MOXMAN_Vfs_IFileStream::READ);
             $out = $dest->open(MOXMAN_Vfs_IFileStream::WRITE);
             // Stream in file to out file
             while (($data = $in->read()) !== "") {
                 $out->write($data);
             }
             $in->close();
             $out->close();
         }
     } else {
         // Copy dir to dir
         $this->copyDir($this, $dest);
     }
 }
Esempio n. 6
0
 /**
  * Saves the image to the specified file.
  *
  * @param stirng $file File instance to save image to.
  * @param int $quality Image quality for jpegs.
  */
 public function saveToFile(MOXMAN_Vfs_IFile $file, $quality = 90)
 {
     if ($file instanceof MOXMAN_Vfs_Local_File) {
         return $this->save($file->getInternalPath());
     }
     // Load image into RAM then write that to file
     // TODO: Replace this once PHP get proper buffers for GD
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     $stream->write($this->getAsString(MOXMAN_Util_PathUtils::getExtension($file->getName()), $quality));
     $stream->close();
 }
Esempio n. 7
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MCE_File $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->exists() && $this->isDirectory()) {
         if (!$this->isFileOrEmptyDir()) {
             throw new MOXMAN_Exception("Copy non empty folders not supported by S3.");
         } else {
             $dest->mkdir();
             return;
         }
     }
     if ($dest instanceof MOXMAN_AmazonS3_File) {
         $fromPath = $this->getInternalPath();
         $toPath = $dest->getInternalPath();
         if ($this->isDirectory()) {
             $fromPath .= "/";
             $toPath .= "/";
         }
         $this->getFileSystem()->getClient()->copy($fromPath, $toPath);
         $dest->removeStatCache();
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }