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; }
/** * 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'; }
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; }
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; }
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; }
/** * 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(); }
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; }
/** * 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; }
/** * 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(); }
<?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']); } }
/** * 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 }
/** * 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; }
/** * 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; } }
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) { global $xoopsUserIsAdmin; if($xoopsUserIsAdmin){ return true; }