示例#1
0
 public function jumpUploaderL10n($langCode)
 {
     //the messages are sent via request because of basic auth problems with a path for the .zip-file that is different from the path the browser authenticated himself against.
     require_once ASCMS_LIBRARY_PATH . '/PEAR/Download.php';
     $download = new HTTP_Download();
     //load correct language file
     $objFWUser = \FWUser::getFWUserObject();
     $download->setFile(ASCMS_CORE_MODULE_PATH . '/Upload/ressources/uploaders/jump/messages_' . $langCode . '.zip');
     $download->setContentType('application/zip');
     $download->send();
     die;
 }
 /**
  * Provide a file for download
  *
  * @return bool true on success else false
  */
 function perform()
 {
     //Get the demanded attachment and send it to the client
     //get the top requested email list attachment folder
     M(MOD_EARCHIVE, 'get_list', array('var' => 'tpl_list', 'lid' => (int) $_GET['lid'], 'fields' => array('folder')));
     //get the requested message attachment folder
     M(MOD_EARCHIVE, 'get_message', array('var' => 'tpl_msg', 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('folder')));
     //get the attachment file name, type
     M(MOD_EARCHIVE, 'get_attach', array('var' => 'tpl_attach', 'aid' => (int) $_GET['aid'], 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('file', 'type')));
     // set params to send http header and content
     $this->B->attach_params = array('file' => SF_RELATIVE_PATH . '/data/earchive/' . $this->B->tpl_list['folder'] . '/' . $this->B->tpl_msg['folder'] . '/' . stripslashes($this->B->tpl_attach['file']), 'contenttype' => $this->B->tpl_attach['type'], 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, stripslashes($this->B->tpl_attach['file'])));
     // stop output buffering
     // we dont need those headers which has been allready sended
     //
     while (@ob_end_clean()) {
     }
     // send header and content
     $error = HTTP_Download::staticSend($this->B->attach_params, false);
     if (TRUE !== $error) {
         trigger_error($error->message . " " . $this->B->attach_params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
     }
     exit;
     // stop application here
     return TRUE;
 }
示例#3
0
 /**
  * Get the image
  * @return        str: hash name / image size (useful for tests)
  */
 public function getImage()
 {
     $sizes = array('small', 'medium', 'large');
     if (is_null($this->size) || !in_array($this->size, $sizes)) {
         $this->size = 'medium';
     }
     $image_download = new HTTP_Download();
     $image_download->setContentType('image/jpeg');
     $image_download->setBufferSize(8192);
     $image_download->setCacheControl('public', 86040000);
     $image_download->setContentDisposition(HTTP_DOWNLOAD_INLINE, $this->size . '.jpg');
     //if art exists stream it to the user, otherwise stream the default placeholder graphics
     if (is_readable($this->art_dir . '/' . $this->hash . '/' . $this->size . '.jpg') === false) {
         $image_download->setFile($this->art_dir . '/placeholder/' . $this->size . '.jpg');
         $this->hash = 'placeholder';
     } else {
         $image_download->setFile($this->art_dir . '/' . $this->hash . '/' . $this->size . '.jpg');
     }
     $this->log(sprintf('Sending Artwork: %s - Size: %s - Filename: %s', $this->hash, $this->size, $this->art_dir . '/' . $this->hash . '/' . $this->size . '.jpg'));
     $image_download->send();
     return $this->hash . '/' . $this->size . '.jpg';
 }
 /**
  * Send a file for downloading
  *
  */
 function _downloadMedia()
 {
     global $_ARRAYLANG;
     if (self::isIllegalFileName($this->getFile)) {
         die($_ARRAYLANG['TXT_MEDIA_FILE_DONT_DOWNLOAD']);
     }
     // The file is already checked (media paths only)
     $file = $this->path . $this->getFile;
     //First, see if the file exists
     if (!is_file($file)) {
         die("<b>404 File not found!</b>");
     }
     $filename = basename($file);
     $file_extension = strtolower(substr(strrchr($filename, "."), 1));
     //This will set the Content-Type to the appropriate setting for the file
     switch ($file_extension) {
         case "pdf":
             $ctype = "application/pdf";
             break;
         case "exe":
             $ctype = "application/octet-stream";
             break;
         case "zip":
             $ctype = "application/zip";
             break;
         case "docx":
         case "doc":
             $ctype = "application/msword";
             break;
         case "xlsx":
         case "xls":
             $ctype = "application/vnd.ms-excel";
             break;
         case "ppt":
             $ctype = "application/vnd.ms-powerpoint";
             break;
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "jpeg":
         case "jpg":
             $ctype = "image/jpg";
             break;
         case "mp3":
             $ctype = "audio/mpeg";
             break;
         case "wav":
             $ctype = "audio/x-wav";
             break;
         case "mpeg":
         case "mpg":
         case "mpe":
             $ctype = "video/mpeg";
             break;
         case "mov":
             $ctype = "video/quicktime";
             break;
         case "avi":
             $ctype = "video/x-msvideo";
             break;
             //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
         //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
         case "phps":
         case "php4":
         case "php5":
         case "php":
             die("<b>Cannot be used for " . $file_extension . " files!</b>");
             break;
         default:
             $ctype = "application/force-download";
     }
     require_once ASCMS_LIBRARY_PATH . '/PEAR/Download.php';
     $dl = new \HTTP_Download(array("file" => $file, "contenttype" => $ctype));
     $dl->send();
     exit;
 }
示例#5
0
 /**
  * Send a bunch of files or directories as an archive
  * 
  * Example:
  * <code>
  *  require_once 'HTTP/Download/Archive.php';
  *  HTTP_Download_Archive::send(
  *      'myArchive.tgz',
  *      '/var/ftp/pub/mike',
  *      HTTP_DOWNLOAD_BZ2,
  *      '',
  *      '/var/ftp/pub'
  *  );
  * </code>
  *
  * @see         Archive_Tar::createModify()
  * @static
  * @access  public
  * @return  mixed   Returns true on success or PEAR_Error on failure.
  * @param   string  $name       name the sent archive should have
  * @param   mixed   $files      files/directories
  * @param   string  $type       archive type
  * @param   string  $add_path   path that should be prepended to the files
  * @param   string  $strip_path path that should be stripped from the files
  */
 static function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
 {
     $tmp = System::mktemp();
     switch ($type = strToUpper($type)) {
         case HTTP_DOWNLOAD_TAR:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp);
             $content_type = 'x-tar';
             break;
         case HTTP_DOWNLOAD_TGZ:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp, 'gz');
             $content_type = 'x-gzip';
             break;
         case HTTP_DOWNLOAD_BZ2:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp, 'bz2');
             $content_type = 'x-bzip2';
             break;
         case HTTP_DOWNLOAD_ZIP:
             include_once 'Archive/Zip.php';
             $arc = new Archive_Zip($tmp);
             $content_type = 'x-zip';
             break;
         default:
             return PEAR::raiseError('Archive type not supported: ' . $type, HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE);
     }
     if ($type == HTTP_DOWNLOAD_ZIP) {
         $options = array('add_path' => $add_path, 'remove_path' => $strip_path);
         if (!$arc->create($files, $options)) {
             return PEAR::raiseError('Archive creation failed.');
         }
     } else {
         if (!($e = $arc->createModify($files, $add_path, $strip_path))) {
             return PEAR::raiseError('Archive creation failed.');
         }
         if (PEAR::isError($e)) {
             return $e;
         }
     }
     unset($arc);
     $dl = new HTTP_Download(array('file' => $tmp));
     $dl->setContentType('application/' . $content_type);
     $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
     return $dl->send();
 }
示例#6
0
 public function send($langId = LANG_ID)
 {
     $objHTTPDownload = new \HTTP_Download();
     $objHTTPDownload->setFile(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteDocumentRootPath() . $this->getSource($langId));
     $objHTTPDownload->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, str_replace('"', '\\"', $this->getSourceName($langId)));
     $objHTTPDownload->setContentType();
     $objHTTPDownload->send('application/force-download');
     exit;
 }
 /**
  * Sends the buffered data to the browser.
  *
  * @param string $filename  The filename for the output file.
  * @param boolean $inline   True if inline, false if attachment.
  */
 function output($filename = 'unknown.pdf', $inline = false)
 {
     /* Check whether the buffer has been flushed already. */
     if ($this->_flushed) {
         return $this->raiseError('The buffer has been flushed already, don\'t use output() in combination with flush().');
     }
     /* Check whether file has been closed. */
     if ($this->_state < 3) {
         $result = $this->close();
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
     }
     /* Check if headers have been sent. */
     if (headers_sent()) {
         return $this->raiseError('Unable to send PDF file, some data has already been output to browser');
     }
     /* If HTTP_Download is not available return a PEAR_Error. */
     if (!(include_once 'HTTP/Download.php')) {
         return $this->raiseError('Missing PEAR package HTTP_Download');
     }
     /* Params for the output. */
     $disposition = $inline ? HTTP_DOWNLOAD_INLINE : HTTP_DOWNLOAD_ATTACHMENT;
     $params = array('data' => $this->_buffer, 'contenttype' => 'application/pdf', 'contentdisposition' => array($disposition, $filename));
     /* Output the file. */
     return HTTP_Download::staticSend($params);
 }
示例#8
0
 function mime_default_download(&$pFileHash)
 {
     global $gBitSystem;
     $ret = FALSE;
     // Check to see if the file actually exists
     if (!empty($pFileHash['source_file']) && is_readable($pFileHash['source_file'])) {
         // if we have PEAR HTTP/Download installed, we make use of it since it allows download resume and download manager access
         // read the docs if you want to enable download throttling and the like
         if (@(include_once 'HTTP/Download.php')) {
             $dl = new HTTP_Download();
             $dl->setLastModified($pFileHash['last_modified']);
             $dl->setFile($pFileHash['source_file']);
             //$dl->setContentDisposition( HTTP_DOWNLOAD_INLINE, $pFileHash['file_name'] );
             $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $pFileHash['file_name']);
             $dl->setContentType($pFileHash['mime_type']);
             $res = $dl->send();
             if (PEAR::isError($res)) {
                 $gBitSystem->fatalError($res->getMessage());
             } else {
                 $ret = TRUE;
             }
         } else {
             // make sure we close off obzip compression if it's on
             if ($gBitSystem->isFeatureActive('site_output_obzip')) {
                 @ob_end_clean();
             }
             // this will get the browser to open the download dialogue - even when the
             // browser could deal with the content type - not perfect, but works
             if ($gBitSystem->isFeatureActive('mime_force_download')) {
                 $pFileHash['mime_type'] = "application/force-download";
             }
             header("Cache Control: ");
             header("Accept-Ranges: bytes");
             header("Content-type: " . $pFileHash['mime_type']);
             header("Content-Disposition: attachment; filename=" . $pFileHash['file_name']);
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", $pFileHash['last_modified']) . " GMT", true, 200);
             header("Content-Length: " . filesize($pFileHash['source_file']));
             header("Content-Transfer-Encoding: binary");
             header("Connection: close");
             readfile($pFileHash['source_file']);
             $ret = TRUE;
             die;
         }
     } else {
         $pFileHash['errors']['no_file'] = tra('No matching file found.');
     }
     return $ret;
 }
示例#9
0
 /**
  * To download a file
  *
  * @param string $file
  *
  * @return null
  */
 public function download($file)
 {
     $objHTTPDownload = new \HTTP_Download();
     $objHTTPDownload->setFile(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteMediaCrmPath() . '/' . $file);
     $objHTTPDownload->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, str_replace('"', '\\"', $file));
     $objHTTPDownload->setContentType();
     $objHTTPDownload->send('application/force-download');
     exit;
 }
示例#10
0
/**
 * Use content (from file, from database, other source...) and pass it to the browser as a file
 *
 * @param string $content
 * @param string $type MIME type
 * @param string $name File name
 * @param integer $size File size
 * @param boolean $force_download Send Content-Disposition: attachment to force 
 *   save dialog
 * @param boolean $die
 * @return boolean
 */
function download_contents($content, $type, $name, $force_download = false, $die = true)
{
    if (!defined('HTTP_LIB_PATH')) {
        require ANGIE_PATH . '/classes/http/init.php';
    }
    // if
    // Prepare variables
    if (empty($name)) {
        $name = basename($path);
    }
    // if
    $disposition = $force_download ? HTTP_DOWNLOAD_ATTACHMENT : HTTP_DOWNLOAD_INLINE;
    // Prepare and send file
    $download = new HTTP_Download();
    $download->setData($content);
    $download->setContentType($type);
    $download->setContentDisposition($disposition, $name);
    $download->send();
    if ($die) {
        die;
    }
    // if
}
示例#11
0
 /**
  * set up Import/Export page
  * call specific function depending on $_GET
  * @access private
  */
 private function manage()
 {
     \Permission::checkAccess(102, 'static');
     //check GETs for action
     $themeId = isset($_GET['export']) ? contrexx_input2raw($_GET['export']) : 0;
     if (!empty($themeId)) {
         $theme = $this->themeRepository->findOneBy(array('id' => $themeId));
         if (!$theme) {
             throw new \Exception('Theme does not exist.');
         }
         $objHTTPDownload = new \HTTP_Download();
         $objHTTPDownload->setFile($this->getExportFilePath($theme));
         $objHTTPDownload->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $theme->getFoldername() . '.zip');
         $objHTTPDownload->setContentType();
         $objHTTPDownload->send('application/force-download');
         exit;
     }
 }
 function downloadFolderByID($id)
 {
     global $DocumentDir;
     require_once 'HTTP/Download.php';
     $apf_folders = DB_DataObject::factory('ApfFolders');
     $apf_folders->setId($id);
     $apf_folders->find();
     $apf_folders->fetch();
     $filename = $apf_folders->getName() . ".tar.gz";
     $foldername = $apf_folders->getDirpath();
     $real_folder_path = $DocumentDir . $foldername;
     HTTP_Download::sendArchive($filename, $real_folder_path, HTTP_DOWNLOAD_TGZ, "", $real_folder_path);
 }
示例#13
0
文件: file.php 项目: nunoluciano/uxcl
}

$saved_filename = rawurldecode($org_filename);

$ua = $_SERVER['HTTP_USER_AGENT'];

if(strstr($ua, "MSIE") && !strstr($ua, 'Opera')){
	$saved_filename = mb_convert_encoding($saved_filename, 'SJIS', 'EUC-JP');
}
else{
	$saved_filename = mb_convert_encoding($saved_filename, 'UTF-8', 'EUC-JP');
}

ini_set('include_path', XOOPS_TRUST_PATH.'/PEAR');
if(include_once('HTTP/Download.php')){
	$download = new HTTP_Download();
	$download->setFile($path_file);
	$download->setCache(false);
	$download->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $saved_filename);
	$download->setContentType('application/octet-stream');
	$download->send();
}
else{
	header("Location: ".XOOPS_URL);
}
exit();

//------------------------------------------------------------------------------

function checkPermission($target, $target_id)
{
示例#14
0
 /**
  * Обработчик действия: Экспорт каталога.
  */
 function Export()
 {
     @set_time_limit(0);
     mk_dir("files/" . DOMAIN . "/tmp");
     clearDir("files/" . DOMAIN . "/tmp");
     require_once "Structures/DataGrid.php";
     require_once "Structures/DataGrid/DataSource/Array.php";
     require_once "Structures/DataGrid/Renderer/CSV.php";
     $categories = array();
     $fields = array();
     $all = array();
     A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort");
     $i = 0;
     while ($row = A::$DB->fetchRow()) {
         if ($row['type'] == 'select' || $row['type'] == 'mselect') {
             if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field=?", $row['field'])) {
                 $row['vars'] = loadList($row['idvar']);
                 foreach ($row['vars'] as $j => $name) {
                     if (is_array($name) && isset($name['name'])) {
                         $row['vars'][$j] = $name['name'];
                     }
                 }
             }
         }
         $row['id'] = $i++;
         $all[$row['field']] = $row;
         if (preg_match("/^category([0-9]{1})\$/i", $row['field'], $matches)) {
             $row['level'] = $matches[1];
             $categories[$row['field']] = $row;
         } else {
             $fields[$row['field']] = $row;
         }
     }
     A::$DB->free();
     $renderer = new Structures_DataGrid_Renderer_CSV();
     $renderer->setOptions(array('delimiter' => ';', 'enclosure' => '"', 'saveToFile' => true, 'useQuotes' => true, 'filename' => "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".csv"));
     $renderer->init();
     $datasource = new Structures_DataGrid_DataSource_Array();
     $datagrid = new Structures_DataGrid();
     $datagrid->bindDataSource($datasource);
     $datagrid->attachRenderer(&$renderer);
     $i = 0;
     $header = array();
     foreach ($all as $field => $frow) {
         $header[$i++] = array('field' => $field, 'label' => mb_convert_encoding($frow['caption'], "Windows-1251", "UTF-8"));
     }
     $renderer->buildHeader($header);
     $cats = array();
     $this->getCategories($cats);
     $i = 0;
     foreach ($cats as $id => $category) {
         A::$DB->query("SELECT * FROM " . SECTION . "_catalog WHERE idcat={$id} ORDER BY name");
         while ($row = A::$DB->fetchRow()) {
             $crow = array();
             for ($j = 0; $j < count($all); $j++) {
                 $crow[$j] = "";
             }
             foreach ($categories as $field => $frow) {
                 if (isset($category['parents'][$frow['level']])) {
                     $crow[$frow['id']] = mb_convert_encoding($category['parents'][$frow['level']], "Windows-1251", "UTF-8");
                 }
             }
             foreach ($fields as $field => $frow) {
                 switch ($frow['type']) {
                     default:
                         $crow[$frow['id']] = isset($row[$field]) ? mb_convert_encoding($row[$field], "Windows-1251", "UTF-8") : '';
                         break;
                     case 'select':
                         $crow[$frow['id']] = !empty($frow['vars'][$row[$field]]) ? mb_convert_encoding($frow['vars'][$row[$field]], "Windows-1251", "UTF-8") : "";
                         break;
                     case 'mselect':
                         $row[$field] = explode(',', $row[$field]);
                         foreach ($row[$field] as $j => $value) {
                             $row[$field][$j] = !empty($frow['vars'][(int) $value]) ? mb_convert_encoding($frow['vars'][(int) $value], "Windows-1251", "UTF-8") : "";
                         }
                         $crow[$frow['id']] = implode(', ', $row[$field]);
                         break;
                     case 'float':
                         $crow[$frow['id']] = round($row[$field], 2);
                         break;
                     case 'image':
                         if (preg_match("/^idimg([0-9]+)\$/i", $field, $mathes)) {
                             $sort = $mathes[1];
                             $images = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort");
                             $crow[$frow['id']] = isset($images[$sort]) ? basename($images[$sort]) : "";
                         }
                         break;
                     case 'file':
                         if (preg_match("/^idfile([0-9]+)\$/i", $field, $mathes)) {
                             $sort = $mathes[1];
                             $files = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort");
                             $crow[$frow['id']] = isset($files[$sort]) ? basename($files[$sort]) : "";
                         }
                         break;
                 }
             }
             if (isset($fields['mprice']) && isset($fields['price'])) {
                 $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array();
                 foreach ($mprices as $mp) {
                     $crow[$fields['mprice']['id']] = mb_convert_encoding($mp['name'], "Windows-1251", "UTF-8");
                     $crow[$fields['price']['id']] = (double) $mp['price'];
                     $renderer->buildRow($i++, $crow);
                 }
                 if (empty($mprices)) {
                     $renderer->buildRow($i++, $crow);
                 }
             } else {
                 $renderer->buildRow($i++, $crow);
             }
         }
         A::$DB->free();
     }
     $renderer->render();
     $renderer->finalize();
     if (filesize($file = "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . '.csv') > 1024 * 2000) {
         return outArchive("files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".tar.gz", $file);
     } else {
         require_once 'HTTP/Download.php';
         $params = array('file' => $file, 'contenttype' => 'text/csv', 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, basename($file)));
         HTTP_Download::staticSend($params, false);
     }
 }
示例#15
0
 /**
  * Stream the original file from anywhere on the user's PC. This function will serve the original file
  * and offer ranges for seeking through the content.
  */
 private function stream_original()
 {
     $this->log('Sending File using Pear HTTP Download');
     $params = array('File' => $this->filename, 'ContentType' => $this->source_type, 'BufferSize' => 32000, 'ContentDisposition' => array(HTTP_DOWNLOAD_INLINE, $this->source_basename));
     $error = HTTP_Download::staticSend($params, false);
 }
示例#16
0
 public function download($document_id)
 {
     require_once 'HTTP/Download.php';
     PHPWS_Core::initModClass('filecabinet', 'Document.php');
     $document = new PHPWS_Document($document_id);
     if (empty($document->id)) {
         $message = 'Document id:' . $document_id;
         if (!empty($_SERVER['HTTP_REFERER'])) {
             $message .= ' request from ' . $_SERVER['HTTP_REFERER'];
         }
         PHPWS_Error::log(FC_DOCUMENT_NOT_FOUND, 'filecabinet', 'Cabinet_Action::download', $message);
         Error::errorPage('404');
     }
     $folder = new Folder($document->folder_id);
     if (!$folder->allow()) {
         $content = dgettext('filecabinet', 'Sorry, the file you requested is off limits.');
         Layout::add($content);
         return;
     }
     $file_path = $document->getPath();
     if (!is_file($file_path)) {
         $message = $file_path;
         if (!empty($_SERVER['HTTP_REFERER'])) {
             $message .= ' request from ' . $_SERVER['HTTP_REFERER'];
         }
         PHPWS_Error::log(FC_DOCUMENT_NOT_FOUND, 'filecabinet', 'Cabinet_Action::download', $message);
         Error::errorPage('404');
     }
     $file_name = preg_replace('/[^\\w]/', '-', $document->getTitle());
     $file_name = preg_replace('/-{2,}/', '-', $file_name);
     $file_name = preg_replace('/-$/', '', $file_name);
     $file_name .= '.' . $document->getExtension();
     $document->downloaded++;
     $document->save();
     $dl = new HTTP_Download();
     $dl->setFile($file_path);
     $dl->setCache(true);
     $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $file_name);
     $dl->setContentType($document->file_type);
     $dl->send();
     exit;
 }
示例#17
0
<?php

// Check to see if the file actually exists
if (is_readable($fileHash['source_file'])) {
    // if we have PEAR HTTP/Download installed, we make use of it since it allows download resume and download manager access
    // read the docs if you want to enable download throttling and the like
    if (@(include_once 'HTTP/Download.php')) {
        $dl = new HTTP_Download();
        $dl->setLastModified($fileHash['last_modified']);
        $dl->setFile($fileHash['source_file']);
        $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $fileHash['filename']);
        $dl->setContentType($fileHash['mime_type']);
        $res = $dl->send();
        if (PEAR::isError($res)) {
            $gBitSystem->fatalError($res->getMessage());
        }
    } else {
        header("Cache Control: ");
        header("Accept-Ranges: bytes");
        header("Content-type: " . $fileHash['mime_type']);
        header("Content-Disposition: attachment; filename=" . $fileHash['filename']);
        header("Last-Modified: " . gmdate("D, d M Y H:i:s", $fileHash['last_modified']) . " GMT", true, 200);
        header("Content-Length: " . filesize($fileHash['source_file']));
        header("Content-Transfer-Encoding: binary");
        header("Connection: close");
        readfile($fileHash['source_file']);
    }
}
示例#18
0
 /**
  * Static send
  *
  * @see     HTTP_Download::HTTP_Download()
  * @see     HTTP_Download::send()
  *
  * @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 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();
 }
<?php

if (!defined('SF_SECURE_INCLUDE')) {
    exit;
}
//Get the demanded attachment and send it to the client
include_once 'HTTP/Download.php';
//get the top requested email list attachment folder
$B->M(MOD_MAILARCHIVER, MAILARCHIVER_LIST, array('var' => 'list', 'lid' => (int) $_GET['lid'], 'fields' => array('folder')));
//get the requested message attachment folder
$B->M(MOD_MAILARCHIVER, MAILARCHIVER_MESSAGE, array('var' => 'msg', 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('folder')));
//get the attachment file name, type
$B->M(MOD_MAILARCHIVER, MAILARCHIVER_ATTACH, array('var' => 'attach', 'aid' => (int) $_GET['aid'], 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('file', 'type')));
// send http header and content
$params = array('file' => './data/mailarchiver/' . $B->list['folder'] . '/' . $B->msg['folder'] . '/' . stripslashes($B->attach['file']), 'contenttype' => $B->attach['type'], 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, stripslashes($B->attach['file'])));
$error = HTTP_Download::staticSend($params, false);
if (TRUE !== $error) {
    trigger_error($error->message . " " . $params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
}
exit;
 function createReport()
 {
     if ($this->class) {
         $methods = get_class_methods($this->class);
         if (in_array($this->report_row, $methods)) {
             $func_type = 'method';
         }
     }
     if (!isset($func_type)) {
         if (function_exists($this->report_row)) {
             $func_type = 'function';
         } else {
             $func_type = 'none';
         }
     }
     $index_set = false;
     $tmp_file = \PHPWS_Text::randomString(10) . time();
     $directory = CACHE_DIRECTORY;
     $file_path = sprintf('%s/%s', $directory, $tmp_file);
     $fp = fopen($file_path, 'w');
     foreach ($this->display_rows as $foo) {
         if ($func_type == 'method') {
             $result = call_user_func(array($foo, $this->report_row));
         } elseif ($func_type == 'function') {
             $result = call_user_func($this->report_row, $foo);
         } else {
             if (is_object($foo)) {
                 $result = PHPWS_Core::stripObjValues($foo);
             } else {
                 $result =& $foo;
             }
         }
         if (!$index_set) {
             $index_keys = array_keys($result);
             $row = fputcsv($fp, $index_keys);
             $index_set = true;
         }
         fputcsv($fp, $result);
         //$row = self::formatCSVRow($result);
         //fwrite($fp, $row);
     }
     fclose($fp);
     $new_file = time() . '_pager.csv';
     require_once 'HTTP/Download.php';
     $dl = new HTTP_Download();
     $dl->setFile($file_path);
     $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $new_file);
     $dl->setContentType('text/csv');
     $dl->send();
     exit;
 }
示例#21
0
        return array();
    }
}
stream_wrapper_register('mytest', 'testStream');
switch ($_GET['what']) {
    case 'file':
        $params['file'] = 'data.txt';
        break;
    case 'resource':
        $params['resource'] = fopen('data.txt', 'rb');
        break;
    case 'stream':
        $params['resource'] = fopen('mytest://data.txt', 'rb');
        break;
    case 'data':
        $params['data'] = file_get_contents('data.txt');
        break;
}
switch ($_GET['op']) {
    case 'static':
        HTTP_Download::staticSend($params);
        break;
    case 'send':
        $h =& new HTTP_Download();
        $h->setParams($params);
        $h->send();
        break;
    case 'arch':
        HTTP_Download::sendArchive('foo.' . $_GET['type'], $_GET['what'], $_GET['type']);
        break;
}
示例#22
0
        }
        break;
    case 'company_logo':
        Debug::Text('Company Logo...', __FILE__, __LINE__, __METHOD__, 10);
        $cf = new CompanyFactory();
        $file_name = $cf->getLogoFileName($current_company->getId());
        Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
        if ($file_name != '' and file_exists($file_name)) {
            $params['file'] = $file_name;
            $params['cache'] = TRUE;
        }
        break;
    case 'primary_company_logo':
        Debug::Text('Primary Company Logo...', __FILE__, __LINE__, __METHOD__, 10);
        $cf = new CompanyFactory();
        $file_name = $cf->getLogoFileName(PRIMARY_COMPANY_ID);
        Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
        if ($file_name != '' and file_exists($file_name)) {
            $params['file'] = $file_name;
            $params['cache'] = TRUE;
        }
        break;
    default:
        break;
}
if (isset($params)) {
    HTTP_Download::staticSend($params);
} else {
    echo "File does not exist, unable to download!<br>\n";
    Debug::writeToLog();
}
示例#23
0
 /**
  * Constructor
  *
  * Set supplied parameters.
  * 
  * @access  public
  * @param   array   $params     associative array of parameters
  * 
  *          <b>one of:</b>
  *                  o 'file'                => path to file for download
  *                  o 'data'                => raw data for download
  *                  o 'resource'            => resource handle for download
  * <br/>
  *          <b>and any of:</b>
  *                  o 'cache'               => whether to allow cs caching
  *                  o 'gzip'                => whether to gzip the download
  *                  o 'lastmodified'        => unix timestamp
  *                  o 'contenttype'         => content type of download
  *                  o 'contentdisposition'  => content disposition
  *                  o 'buffersize'          => amount of bytes to buffer
  *                  o 'throttledelay'       => amount of secs to sleep
  * 
  * <br />
  * 'Content-Disposition' is not HTTP compliant, but most browsers 
  * follow this header, so it was borrowed from MIME standard.
  * 
  * It looks like this: <br />
  * "Content-Disposition: attachment; filename=example.tgz".
  * 
  * @see HTTP_Download::setContentDisposition()
  */
 function HTTP_Download($params = array())
 {
     HTTP_Download::__construct($params);
 }
示例#24
0
 protected function runUntrustedAction($action)
 {
     switch ($action) {
         case 'backup':
             include_once 'HTTP/Download.php';
             include_once 'Archive/Tar.php';
             if (!$this->data_engine->dump(TIP::buildDataPath('dump'))) {
                 TIP::notifyError('backup');
                 return false;
             }
             $tar_file = TIP::buildCachePath($this->id . '-' . TIP::formatDate('date_sql') . '.tar.gz');
             $tar_object = new Archive_Tar($tar_file, 'gz');
             $result = $tar_object->createModify(TIP::buildDataPath(), '', TIP::buildPath());
             unset($tar_object);
             if ($result !== true) {
                 return false;
             }
             HTTP_Download::staticSend(array('file' => $tar_file, 'contenttype' => 'application/x-gzip', 'contentdisposition' => HTTP_DOWNLOAD_ATTACHMENT));
             exit;
     }
     return null;
 }
<?php

/* attach Template. See also /view/class.view_attach.php */
?>

<?php 
/* Only allow calling this template from whithin the application */
if (!defined('SF_SECURE_INCLUDE')) {
    exit;
}
?>
 

<?php 
// stop output buffering
// we dont need those headers which has been allready sended
//
while (@ob_end_clean()) {
}
// send header and content
$error = HTTP_Download::staticSend($B->attach_params, false);
if (TRUE !== $error) {
    trigger_error($error->message . " " . $B->attach_params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR);
}
exit;