Ejemplo n.º 1
0
 /**
  * @ignore
  */
 public function __construct($uSource = null, $uOriginalFilename = null)
 {
     $this->source = $uSource;
     $this->background = array(255, 255, 255, 0);
     if ($this->source === null) {
         $this->sa = 1;
     } else {
         $tData = getimagesize($this->source);
         $this->sw = $tData[0];
         $this->sh = $tData[1];
         $this->sa = $this->sw / $this->sh;
         // get the source file extension
         if ($uOriginalFilename === null) {
             $uOriginalFilename = $this->source;
         }
         $this->filename = pathinfo($this->source, PATHINFO_FILENAME);
         $this->extension = pathinfo($uOriginalFilename, PATHINFO_EXTENSION);
         $this->mime = Mime::getType($this->extension);
         $this->size = filesize($this->source);
         // calculate a hash - used for cache files, etc
         $this->hash = Media::calculateHash($this->filename, $this->sw, $this->sh) . '.' . $this->extension;
         if ($this->extension === 'jpeg' || $this->extension === 'jpe' || $this->extension === 'jpg') {
             $this->image = imagecreatefromjpeg($this->source);
         } elseif ($this->extension === 'gif') {
             $this->image = imagecreatefromgif($this->source);
         } elseif ($this->extension === 'png') {
             $this->image = imagecreatefrompng($this->source);
             imagealphablending($this->image, true);
             imagesavealpha($this->image, true);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @ignore
  */
 public function addAttachment($uFilename, $uPath, $uEncoding = 'base64', $uType = null)
 {
     $tMimepart = new Mimepart();
     $tMimepart->filename = $uFilename;
     if ($uType !== null) {
         $tMimepart->type = $uType;
     } else {
         $tExtension = pathinfo($uFilename, PATHINFO_EXTENSION);
         $tMimepart->type = Mime::getType($tExtension, 'application/octet-stream');
     }
     $tMimepart->transferEncoding = $uEncoding;
     $tMimepart->load($uPath);
     $this->parts[] = $tMimepart;
     return $tMimepart;
 }
Ejemplo n.º 3
0
 /**
  * @ignore
  *
  * @throws \Exception
  */
 public static function getDirectory($uSelectedDirectory, $uSubPath)
 {
     $tPath = rtrim(Io::translatePath($uSelectedDirectory['path']), '/');
     foreach (explode('/', ltrim($uSubPath, '/')) as $tSubDirectory) {
         if (strlen($tSubDirectory) === 0 || $tSubDirectory[0] === '.') {
             break;
         }
         $tPath .= '/' . $tSubDirectory;
     }
     if (!file_exists($tPath)) {
         throw new \Exception('asset not found.');
     }
     if (isset($uSelectedDirectory['autoViewer/defaultPage'])) {
         if (is_dir($tPath)) {
             $tPath = rtrim($tPath, '/') . '/' . $uSelectedDirectory['autoViewer/defaultPage'];
         }
         if (isset($uSelectedDirectory['autoViewer/header'])) {
             Views::viewFile($uSelectedDirectory['autoViewer/header']);
         }
         Views::viewFile($tPath);
         if (isset($uSelectedDirectory['autoViewer/footer'])) {
             Views::viewFile($uSelectedDirectory['autoViewer/footer']);
         }
         return true;
     }
     if (is_dir($tPath)) {
         return false;
     }
     header('Content-Type: ' . Mime::getType(pathinfo($tPath, PATHINFO_EXTENSION)), true);
     header('Content-Transfer-Encoding: binary', true);
     // header('ETag: "' . md5_file($tPath) . '"', true);
     readfile($tPath);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @ignore
  */
 public static function sendFile($uFilePath, $uAttachment = false, $uFindMimeType = true)
 {
     $tExtension = pathinfo($uFilePath, PATHINFO_EXTENSION);
     if ($uFindMimeType) {
         $tType = Mime::getType($tExtension);
     } else {
         $tType = 'application/octet-stream';
     }
     self::sendHeaderCache(-1);
     header('Accept-Ranges: bytes', true);
     header('Content-Type: ' . $tType, true);
     if ($uAttachment) {
         header('Content-Disposition: attachment; filename=' . pathinfo($uFilePath, PATHINFO_BASENAME) . ';', true);
     }
     header('Content-Transfer-Encoding: binary', true);
     //! filesize problem
     // header('Content-Length: ' . filesize($uFilePath), true);
     header('ETag: "' . md5_file($uFilePath) . '"', true);
     readfile($uFilePath, false);
     Framework::end(0);
 }