/**
  * Static send
  *
  * @see     HTTP_Download::staticSend()
  * 
  * @static
  * @access  public
  * @return  mixed   Returns true on success or PEAR_Error on failure.
  * @param   array   $params     associative array of parameters
  * @param   bool    $guess      whether HTTP_Download::guessContentType()
  *                               should be called
  */
 function staticSend($params, $guess = false)
 {
     $d = new Codendi_HTTP_Download();
     $e = $d->setParams($params);
     if (PEAR::isError($e)) {
         return $e;
     }
     if ($guess) {
         $e = $d->guessContentType();
         if (PEAR::isError($e)) {
             return $e;
         }
     }
     return $d->send();
 }
Example #2
0
 /**
  * download : download the file, i.e. print it to stdout
  *
  * WARNING : this function does not check permissions, nor does it log the download  
  *  
  * @return boolean true if the user has permissions to download the file, false otherwise
  */
 function download()
 {
     $file_location = $this->getFileLocation();
     if (false && class_exists('Codendi_HTTP_Download')) {
         return !PEAR::isError(Codendi_HTTP_Download::staticSend(array('file' => $this->getFileLocation(), 'cache' => false, 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, basename($this->getFileName())), 'buffersize' => 8192)));
     } else {
         //old school to be removed in 4.2
         $file_size = $this->getFileSize();
         // Make sure this URL is not cached anywhere otherwise download
         // would be wrong
         header('Expires: Mon, 26 Nov 1962 00:00:00 GMT');
         header('Pragma: private');
         header('Cache-control: private, must-revalidate');
         header("Content-Type: application/octet-stream");
         header('Content-Disposition: attachment; filename="' . basename($this->getFileName()) . '"');
         if ($file_size > 0) {
             header("Content-Length:  {$file_size}");
         }
         header("Content-Transfer-Encoding: binary\n");
         //reset time limit for big files
         set_time_limit(0);
         flush();
         // Now transfer the file to the client
         // Check the 2 GB limit (2^31 -1)
         if ($file_size > 2147483647) {
             if ($fp = popen("/bin/cat {$file_location}", "rb")) {
                 $blocksize = 2 << 20;
                 //2M chunks
                 while (!feof($fp)) {
                     print fread($fp, $blocksize);
                 }
                 flush();
                 pclose($fp);
             } else {
                 return false;
             }
         } else {
             if (readfile($file_location) == false) {
                 return false;
             }
         }
         return true;
     }
 }