本文整理汇总了PHP中FileManager::viewFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::viewFile方法的具体用法?PHP FileManager::viewFile怎么用?PHP FileManager::viewFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::viewFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: files
/**
* Display the files associated with a journal.
*/
function files($args)
{
$this->validate();
$this->setupTemplate(true);
import('lib.pkp.classes.file.FileManager');
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign('pageHierarchy', array(array(Request::url(null, 'manager'), 'manager.journalManagement')));
FilesHandler::parseDirArg($args, $currentDir, $parentDir);
$currentPath = FilesHandler::getRealFilesDir($currentDir);
if (@is_file($currentPath)) {
$fileMgr = new FileManager();
if (Request::getUserVar('download')) {
$fileMgr->downloadFile($currentPath);
} else {
$fileMgr->viewFile($currentPath, FilesHandler::fileMimeType($currentPath));
}
} else {
$files = array();
if ($dh = @opendir($currentPath)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$filePath = $currentPath . '/' . $file;
$isDir = is_dir($filePath);
$info = array('name' => $file, 'isDir' => $isDir, 'mimetype' => $isDir ? '' : FilesHandler::fileMimeType($filePath), 'mtime' => filemtime($filePath), 'size' => $isDir ? '' : FileManager::getNiceFileSize(filesize($filePath)));
$files[$file] = $info;
}
}
closedir($dh);
}
ksort($files);
$templateMgr->assign_by_ref('files', $files);
$templateMgr->assign('currentDir', $currentDir);
$templateMgr->assign('parentDir', $parentDir);
$templateMgr->assign('helpTopicId', 'journal.managementPages.fileBrowser');
$templateMgr->display('manager/files/index.tpl');
}
}
示例2: viewFileContents
/**
* Output PDF generated from the XML/XSL/FO source to browser
* This function performs any necessary filtering, like image URL replacement.
* @return string
*/
function viewFileContents()
{
import('lib.pkp.classes.file.FileManager');
$pdfFileName = CacheManager::getFileCachePath() . DIRECTORY_SEPARATOR . 'fc-xsltGalley-' . str_replace(FileManager::parseFileExtension($this->getFileName()), 'pdf', $this->getFileName());
// if file does not exist or is outdated, regenerate it from FO
if (!FileManager::fileExists($pdfFileName) || filemtime($pdfFileName) < filemtime($this->getFilePath())) {
// render XML into XSL-FO
$cache =& $this->_getXSLTCache($this->getFileName() . '-' . $this->getId());
$contents = $cache->getContents();
if ($contents == "") {
return false;
}
// if for some reason the XSLT failed, show original file
// Replace image references
$images =& $this->getImageFiles();
if ($images !== null) {
// TODO: this should "smart replace" the file path ($this->getFilePath()) in the XSL-FO
// in lieu of requiring XSL parameters, and transparently for FO that are hardcoded
foreach ($images as $image) {
$contents = preg_replace('/src\\s*=\\s*"([^"]*)' . preg_quote($image->getOriginalFileName()) . '([^"]*)"/i', 'src="${1}' . dirname($this->getFilePath()) . DIRECTORY_SEPARATOR . $image->getFileName() . '$2"', $contents);
}
}
// Replace supplementary file references
$this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
$suppFiles = $this->suppFileDao->getSuppFilesByArticle($this->getArticleId());
if ($suppFiles) {
$journal =& Request::getJournal();
foreach ($suppFiles as $supp) {
$suppUrl = Request::url(null, 'article', 'downloadSuppFile', array($this->getArticleId(), $supp->getBestSuppFileId($journal)));
$contents = preg_replace('/external-destination\\s*=\\s*"([^"]*)' . preg_quote($supp->getOriginalFileName()) . '([^"]*)"/i', 'external-destination="' . $suppUrl . '"', $contents);
}
}
// create temporary FO file and write the contents
import('classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$tempFoName = $temporaryFileManager->filesDir . $this->getFileName() . '-' . $this->getId() . '.fo';
$temporaryFileManager->writeFile($tempFoName, $contents);
// perform %fo and %pdf replacements for fully-qualified shell command
$journal =& Request::getJournal();
$xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
$fopCommand = str_replace(array('%fo', '%pdf'), array($tempFoName, $pdfFileName), $xmlGalleyPlugin->getSetting($journal->getId(), 'externalFOP'));
// check for safe mode and escape the shell command
if (!ini_get('safe_mode')) {
$fopCommand = escapeshellcmd($fopCommand);
}
// run the shell command and get the results
exec($fopCommand . ' 2>&1', $contents, $status);
// if there is an error, spit out the shell results to aid debugging
if ($status != false) {
if ($contents != '') {
echo implode("\n", $contents);
$cache->flush();
// clear the XSL cache in case it's a FO error
return true;
} else {
return false;
}
}
// clear the temporary FO file
FileManager::deleteFile($tempFoName);
}
// use FileManager to send file to browser
FileManager::viewFile($pdfFileName, $this->getFileType());
return true;
}