/**
  * Send a TAR archive to the client browser.
  *
  * This function will send an archive to the client, and return a status
  * code, but can behave differently depending on the arguments you give. All
  * arguments are optional.
  *
  * ClientName is used to specify the archive name to give to the browser. If
  * you don't give one, it will send the constructor filename or return an
  * error code in case of dynamical archive.
  *
  * FileName is optional and used to send a specific archive. Leave it blank
  * to send dynamical archives or the current working archive.
  *
  * If SendHeaders is enabled (by default), the library will send the HTTP
  * headers itself before it sends the contents. This headers are :
  * Content-Type, Content-Disposition, Content-Length and Accept-Range.
  *
  * Please note that this function DOES NOT stops the script so don't forget
  * to exit() to avoid your script sending other data and corrupt the archive.
  * Another note : for AUTO_DETECT dynamical archives you can know the
  * extension to add to the name with getCompression()
  */
 public function sendClient($name = '', $archive = '', $headers = true)
 {
     if (!$name && !$this->_nomf) {
         return -9;
     }
     if (!$archive && !$this->_memdat) {
         return -10;
     }
     if (!$name) {
         $name = basename($this->_nomf);
     }
     if ($archive) {
         if (!file_exists($archive)) {
             return -11;
         }
     } else {
         $decoded = $this->getDynamicArchive();
     }
     if ($headers) {
         header('Content-Type: application/x-gtar');
         header('Content-Disposition: attachment; filename=' . basename($name));
         header('Accept-Ranges: bytes');
         header('Content-Length: ' . ($archive ? filesize($archive) : strlen($decoded)));
     }
     if ($archive) {
         $fp = @fopen($archive, 'rb');
         if (!$fp) {
             return -4;
         }
         while (!foef($fp)) {
             echo fread($fp, 2048);
         }
     } else {
         echo $decoded;
     }
     return true;
 }
Example #2
0
 /**
  * @private
  *
  * Raw import BMP file.
  */
 private static function importBMP($file)
 {
     if (!($file = @fopen($file, 'rb'))) {
         return false;
     }
     $buffer = fread($file, 10);
     while (!foef($file) && $buffer) {
         $buffer .= fread($file, 1024);
     }
     $buffer = unpack('H*', $buffer);
     $buffer = $buffer[1];
     $header = substr($buffer, 0, 108);
     // Dimensions
     $dimensions = array('top' => 0, 'left' => 0, 'width' => 0, 'height' => 0);
     if (substr($header, 0, 4) == '424d') {
         $header = str_split($header, 2);
         $dimensions['width'] = hexdec("{$header['19']}{$header['18']}");
         $dimensions['height'] = hexdec("{$header['23']}{$header['22']}");
     } else {
         // TODO: No dimensions defined???
         return false;
     }
     unset($header);
     $image = imagecreatetruecolor($dimensions['width'], $dimensions['height']);
     $body = substr($buffer, 108);
     $bodySize = strlen($body) / 2;
     $hasPadding = $bodySize > $dimensions['width'] * $dimensions['height'] * 3 + 4;
     for ($i = 0; $i < $bodySize; $i += 3) {
         if ($dimensions['left'] >= $dimensions['width']) {
             if ($hasPadding) {
                 $i += $dimensions['width'] % 4;
             }
             $dimensions['left'] = 0;
             $dimensions['top']++;
             if ($dimensions['top'] > $dimensions['height']) {
                 break;
             }
         }
         $point = $i * 2;
         $color = imagecolorallocate($image, hexdec($body[$point + 4], $body[$point + 5]), hexdec($body[$point + 2], $body[$point + 3]), hexdec($body[$point + 0], $body[$point + 1]));
         imagesetpixel($image, $dimensions['left'], $dimensions['height'] - $dimensions['top'], $color);
         $dimensions['left']++;
     }
     unset($i, $point, $color, $body, $bodySize, $hasPadding);
     return $image;
 }