本文整理汇总了PHP中Controller::sendFileToBrowser方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::sendFileToBrowser方法的具体用法?PHP Controller::sendFileToBrowser怎么用?PHP Controller::sendFileToBrowser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller::sendFileToBrowser方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Return if there are no files
*
* @return string
*/
public function generate()
{
// Use the home directory of the current user as file source
if ($this->useHomeDir && FE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
if ($this->User->assignDir && $this->User->homeDir) {
$this->multiSRC = array($this->User->homeDir);
}
} else {
$this->multiSRC = deserialize($this->multiSRC);
}
// Return if there are no files
if (!is_array($this->multiSRC) || empty($this->multiSRC)) {
return '';
}
// Get the file entries from the database
$this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
if ($this->objFiles === null) {
if (!\Validator::isUuid($this->multiSRC[0])) {
return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
while ($this->objFiles->next()) {
if ($file == $this->objFiles->path || dirname($file) == $this->objFiles->path) {
\Controller::sendFileToBrowser($file);
}
}
$this->objFiles->reset();
}
return parent::generate();
}
示例2: download
/**
* Send a file to browser and increase download counter
*
* @param string $strFile
*/
protected function download($strFile)
{
if (TL_MODE == 'FE' && $this->downloads_remaining !== '') {
\Database::getInstance()->prepare("UPDATE " . static::$strTable . " SET downloads_remaining=(downloads_remaining-1) WHERE id=?")->execute($this->id);
}
\Controller::sendFileToBrowser($strFile);
}
示例3: generate
/**
* Return if the file does not exist
* @return string
*/
public function generate()
{
// Return if there is no file
if ($this->singleSRC == '') {
return '';
}
$objFile = \FilesModel::findByUuid($this->singleSRC);
if ($objFile === null) {
if (!\Validator::isUuid($this->singleSRC)) {
return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
return '';
}
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
// Return if the file type is not allowed
if (!in_array($objFile->extension, $allowedDownload)) {
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFile->path) {
\Controller::sendFileToBrowser($file);
}
$this->singleSRC = $objFile->path;
return parent::generate();
}
示例4: generate
/**
* Return if there are no files
* @return string
*/
public function generate()
{
// Use the home directory of the current user as file source
if ($this->useHomeDir && FE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
if ($this->User->assignDir && $this->User->homeDir) {
$this->folderSRC = $this->User->homeDir;
}
}
// Return if there is no folder defined
if (empty($this->folderSRC)) {
return '';
}
// Get the folders from the database
$this->objFolder = \FilesModel::findByUuid($this->folderSRC);
if ($this->objFolder === null) {
if (!\Validator::isUuid($this->folderSRC[0])) {
return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
if (strpos(dirname($file), $this->objFolder->path) !== FALSE) {
\Controller::sendFileToBrowser($file);
}
}
return parent::generate();
}
示例5: __construct
public function __construct($arrAttributes)
{
parent::__construct();
$this->arrData = $arrAttributes;
$file = \Input::get('file', true);
// Send the file to the browser
if ($file != '') {
if (!static::isAllowedDownload($file)) {
header('HTTP/1.1 403 Forbidden');
die('No file access.');
}
\Controller::sendFileToBrowser($file);
}
global $objPage;
$this->blnIsXhtml = $objPage->outputFormat == 'xhtml';
$this->loadDcaConfig();
}
示例6: generate
public function generate(WatchlistItemModel $objItem, Watchlist $objWatchlist)
{
global $objPage;
$objFileModel = \FilesModel::findById($objItem->uuid);
if ($objFileModel === null) {
return;
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFileModel->path) {
\Controller::sendFileToBrowser($file);
}
$objFile = new \File($objFileModel->path, true);
$objContent = \ContentModel::findByPk($objItem->cid);
$objT = new \FrontendTemplate('watchlist_view_download');
$objT->setData($objFileModel->row());
$linkTitle = specialchars($objFile->name);
// use generate for download & downloads as well
if ($objContent->type == 'download' && $objContent->linkTitle != '') {
$linkTitle = $objContent->linkTitle;
}
$arrMeta = deserialize($objFileModel->meta);
// Language support
if (($arrLang = $arrMeta[$GLOBALS['TL_LANGUAGE']]) != '') {
$linkTitle = $arrLang['title'] ? $arrLang['title'] : $linkTitle;
}
$strHref = \Controller::generateFrontendUrl($objPage->row());
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path);
$objT->link = ($objItemTitle = $objItem->title) ? $objItemTitle : $linkTitle;
$objT->title = specialchars($objContent->titleText ?: $linkTitle);
$objT->href = $strHref;
$objT->filesize = \System::getReadableSize($objFile->filesize, 1);
$objT->icon = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon;
$objT->mime = $objFile->mime;
$objT->extension = $objFile->extension;
$objT->path = $objFile->dirname;
$objT->actions = $this->generateEditActions($objItem, $objWatchlist);
return $objT->parse();
}
示例7: generate
/**
* Return if the file does not exist
*
* @return string
*/
public function generate()
{
// Return if there is no file
if ($this->singleSRC == '') {
return '';
}
$objFile = \FilesModel::findByUuid($this->singleSRC);
if ($objFile === null) {
return '';
}
$allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Return if the file type is not allowed
if (!in_array($objFile->extension, $allowedDownload)) {
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFile->path) {
\Controller::sendFileToBrowser($file);
}
$this->singleSRC = $objFile->path;
return parent::generate();
}
示例8: addDownloadsFromProductDownloadsToTemplate
public static function addDownloadsFromProductDownloadsToTemplate($objTemplate)
{
$arrDownloads = array();
// array for downloadfiles from db
$arrFiles = array();
// contains queryresults from db
$strTable = "tl_iso_download";
// name of download table
global $objPage;
$arrOptions = array('order' => 'sorting ASC');
$arrFiles = \Isotope\Model\Download::findBy('pid', $objTemplate->id, $arrOptions);
if ($arrFiles === null) {
return $arrDownloads;
}
while ($arrFiles->next()) {
$objModel = \FilesModel::findByUuid($arrFiles->singleSRC);
if ($objModel === null) {
if (!\Validator::isUuid($arrFiles->singleSRC)) {
$objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
} elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
$objFile = new \File($objModel->path, true);
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFile->path) {
\Controller::sendFileToBrowser($file);
}
$arrMeta = \Frontend::getMetaData($objModel->meta, $objPage->language);
if (empty($arrMeta)) {
if ($objPage->rootFallbackLanguage !== null) {
$arrMeta = \Frontend::getMetaData($objModel->meta, $objPage->rootFallbackLanguage);
}
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path);
$objDownload = new \stdClass();
$objDownload->id = $objModel->id;
$objDownload->uuid = $objModel->uuid;
$objDownload->name = $objFile->basename;
$objDownload->formedname = preg_replace(array('/_/', '/.\\w+$/'), array(' ', ''), $objFile->basename);
$objDownload->title = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename));
$objDownload->link = $arrMeta['title'];
$objDownload->filesize = \System::getReadableSize($objFile->filesize, 1);
$objDownload->icon = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon;
$objDownload->href = $strHref;
$objDownload->mime = $objFile->mime;
$objDownload->extension = $objFile->extension;
$objDownload->path = $objFile->dirname;
$objDownload->class = 'isotope-download isotope-download-file';
$objT = new \FrontendTemplate('isotope_download_from_attribute');
$objT->setData((array) $objDownload);
$objDownload->output = $objT->parse();
$arrDownloads[] = $objDownload;
}
}
$objTemplate->downloads = $arrDownloads;
}
示例9: handleDownload
/**
* Handle downloads
* @return bool return true, or false if the file does not exist
*/
protected function handleDownload()
{
$objFile = \HeimrichHannot\Haste\Util\Files::getFileFromUuid($this->fileSRC);
if ($objFile === null) {
return false;
}
$allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Return if the file type is not allowed
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
return false;
}
$arrMeta = $this->getMetaFromFile($objFile);
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFile->path) {
\Controller::sendFileToBrowser($file);
}
$this->setHref(\Environment::get('request'));
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $this->getHref())) {
$this->setHref(preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $this->getHref()));
}
$this->setHref($this->getHref() . (\Config::get('disableAlias') || strpos($this->getHref(), '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path));
$this->setTitle(sprintf($GLOBALS['TL_LANG']['MSC']['linkteaser']['downloadTitle'], $arrMeta['title']));
$this->setLink(sprintf($this->getLink(), $arrMeta['title']));
return true;
}
示例10: generate
/**
* Return if the file does not exist
* @return string
*/
public function generate()
{
$this->arrDownloadarchives = unserialize($this->downloadarchive);
if ($this->downloadarchive != null && !is_array($this->arrDownloadarchives)) {
$this->arrDownloadarchives = array($this->downloadarchive);
}
// Return if there are no categories
if (count($this->arrDownloadarchives) < 1) {
return '';
}
if (TL_MODE == 'BE') {
$title = array();
foreach ($this->arrDownloadarchives as $archive) {
$objDownloadarchivee = \FelixPfeiffer\Downloadarchive\DownloadarchiveModel::findByPk($archive);
$title[] = $objDownloadarchivee->title;
}
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['downloadarchive'][0]) . ' - ' . implode(", ", $title) . ' ###';
return $objTemplate->parse();
}
$this->checkForPublishedArchives();
$this->import('FrontendUser', 'User');
foreach ($this->arrDownloadarchives as $archive) {
$objFiles = \FelixPfeiffer\Downloadarchive\DownloadarchiveitemsModel::findPublishedByPid($archive);
if ($objFiles === null) {
continue;
}
while ($objFiles->next()) {
$objFile = \FilesModel::findByUuid($objFiles->singleSRC);
if (!file_exists(TL_ROOT . '/' . $objFile->path) || $objFiles->guests && FE_USER_LOGGED_IN || $objFiles->protected == 1 && !FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN) {
continue;
}
$arrGroups = deserialize($objFiles->groups);
if ($objFiles->protected == 1 && is_array($arrGroups) && count(array_intersect($this->User->groups, $arrGroups)) < 1 && !BE_USER_LOGGED_IN) {
continue;
}
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
if (!in_array($objFile->extension, $allowedDownload)) {
continue;
}
$arrFile = $objFiles->row();
$filename = $objFile->path;
$arrFile['filename'] = $filename;
$this->arrDownloadfiles[$archive][$filename] = $arrFile;
}
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
foreach ($this->arrDownloadfiles as $k => $archive) {
if (array_key_exists($file, $archive)) {
\Controller::sendFileToBrowser($file);
}
}
}
return parent::generate();
}
示例11: generate
/**
* Generate download attributes
* @param IsotopeProduct
* @return string
*/
public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
{
global $objPage;
$arrFiles = deserialize($objProduct->{$this->field_name});
// Return if there are no files
if (empty($arrFiles) || !is_array($arrFiles)) {
return '';
}
// Get the file entries from the database
$objFiles = \FilesModel::findMultipleByIds($arrFiles);
if (null === $objFiles) {
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
while ($objFiles->next()) {
if ($file == $objFiles->path || dirname($file) == $objFiles->path) {
\Controller::sendFileToBrowser($file);
}
}
$objFiles->reset();
}
$files = array();
$auxDate = array();
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
// Get all files
while ($objFiles->next()) {
// Continue if the files has been processed or does not exist
if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
// Single files
if ($objFiles->type == 'file') {
$objFile = new \File($objFiles->path, true);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFiles->path);
// Add the image
$files[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
} else {
$objSubfiles = \FilesModel::findByPid($objFiles->id);
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
continue;
}
$objFile = new \File($objSubfiles->path, true);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = \Frontend::getMetaData($objSubfiles->meta, $objPage->language);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objSubfiles->path);
// Add the image
$files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
}
}
}
// Sort array
$sortBy = $arrOptions['sortBy'] ?: $this->sortBy;
switch ($sortBy) {
default:
case 'name_asc':
uksort($files, 'basename_natcasecmp');
break;
case 'name_desc':
uksort($files, 'basename_natcasercmp');
break;
case 'date_asc':
array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
//.........这里部分代码省略.........
示例12: resolveFiles
/**
* Process all folders and resolve to a valid file list.
*
* @return ToolboxFile
*/
public function resolveFiles()
{
// Step 1.: fetch all files.
$this->collectFiles();
// TODO: check if downloading is allowed and send file to browser then
// See https://github.com/MetaModels/attribute_file/issues/6 for details of how to implement this.
if (!$this->getShowImages() && ($strFile = \Input::get('file')) && in_array($strFile, $this->foundFiles)) {
\Controller::sendFileToBrowser($strFile);
}
// Step 2.: Fetch all meta data for the found files.
$this->parseMetaFiles();
// Step 3.: fetch additional information like modification time etc. and prepare the output buffer.
$this->fetchAdditionalData();
return $this;
}