本文整理汇总了PHP中FileManager::downloadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::downloadFile方法的具体用法?PHP FileManager::downloadFile怎么用?PHP FileManager::downloadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::downloadFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: files
/**
* Display the files associated with a journal.
* @param $args array
* @param $request PKPRequest
*/
function files($args, $request)
{
$this->validate();
$this->setupTemplate($request, true);
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$templateMgr = TemplateManager::getManager($request);
$this->_parseDirArg($args, $currentDir, $parentDir);
$currentPath = $this->_getRealFilesDir($request, $currentDir);
if (@is_file($currentPath)) {
if ($request->getUserVar('download')) {
$fileManager->downloadFile($currentPath);
} else {
$fileManager->downloadFile($currentPath, $this->_fileMimeType($currentPath), true);
}
} 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 ? '' : $this->_fileMimeType($filePath), 'mtime' => filemtime($filePath), 'size' => $isDir ? '' : $fileManager->getNiceFileSize(filesize($filePath)));
$files[$file] = $info;
}
}
closedir($dh);
}
ksort($files);
$templateMgr->assign('files', $files);
$templateMgr->assign('currentDir', $currentDir);
$templateMgr->assign('parentDir', $parentDir);
$templateMgr->display('manager/files/index.tpl');
}
}
示例2: deposits
/**
* Provide an endpoint for the PLN staging server to retrieve a deposit
* @param array $args
* @param Request $request
*/
function deposits($args, &$request)
{
$journal =& $request->getJournal();
$depositDao =& DAORegistry::getDAO('DepositDAO');
$fileManager = new FileManager();
$dispatcher = $request->getDispatcher();
$depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0];
// sanitize the input
if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) {
error_log(__("plugins.generic.pln.error.handler.uuid.invalid"));
$dispatcher->handle404();
return FALSE;
}
$deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid);
if (!$deposit) {
error_log(__("plugins.generic.pln.error.handler.uuid.notfound"));
$dispatcher->handle404();
return FALSE;
}
$depositPackage = new DepositPackage($deposit, null);
$depositBag = $depositPackage->getPackageFilePath();
if (!$fileManager->fileExists($depositBag)) {
error_log("plugins.generic.pln.error.handler.file.notfound");
$dispatcher->handle404();
return FALSE;
}
return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE);
}
示例3: downloadFile
/**
* Download a file.
* @param $fileId int the file id of the file to download
* @param $inline print file as inline instead of attachment, optional
* @return boolean
*/
function downloadFile($fileId, $userId, $inline = false)
{
$temporaryFile =& $this->getFile($fileId, $userId);
if (isset($temporaryFile)) {
$filePath = $this->filesDir . $temporaryFile->getFileName();
return parent::downloadFile($filePath, null, $inline);
} else {
return false;
}
}
示例4: deposits
/**
* Provide an endpoint for the PLN staging server to retrieve a deposit
* @param array $args
* @param Request $request
*/
function deposits($args, &$request)
{
$journal =& $request->getJournal();
$plnPlugin =& PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME);
$depositDao =& DAORegistry::getDAO('DepositDAO');
$fileManager = new FileManager();
$depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0];
// sanitize the input
if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) {
return FALSE;
}
$deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid);
if (!$deposit) {
return FALSE;
}
$depositPackage = new DepositPackage($deposit);
$depositBag = $depositPackage->getPackageFilePath();
if (!$fileManager->fileExists($depositBag)) {
return FALSE;
}
//TODO: Additional check here for journal UUID in HTTP header from staging server
return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE);
}
示例5: 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');
}
}
示例6: display
/**
* Display the plugin.
* @param $args array
* @param $request PKPRequest
*/
function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$press = $request->getPress();
parent::display($args, $request);
$templateMgr->assign('plugin', $this);
switch (array_shift($args)) {
case 'index':
case '':
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
break;
case 'export':
$exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser());
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
}
}
示例7: viewFile
/**
* View a file inline (variant of downloadFile).
* @see FileManager::downloadFile
*/
function viewFile($filePath, $type = null)
{
FileManager::downloadFile($filePath, $type, true);
}
示例8: downloadFile
/**
* Download a file.
* @param $fileId int the file id of the file to download
* @param $inline print file as inline instead of attachment, optional
* @return boolean
*/
function downloadFile($fileId, $inline = false)
{
$issueFileDao =& DAORegistry::getDAO('IssueFileDAO');
$issueFile =& $issueFileDao->getIssueFile($fileId);
if ($issueFile) {
$fileType = $issueFile->getFileType();
$filePath = $this->getFilesDir() . $this->contentTypeToPath($issueFile->getContentType()) . '/' . $issueFile->getFileName();
return parent::downloadFile($filePath, $fileType, $inline);
} else {
return false;
}
}
示例9: downloadFilesArchive
/**
* Download all monograph files as an archive
* @param $monographId integer
* @param $monographFiles ArrayItemIterator
* @return boolean
*/
function downloadFilesArchive($monographId, &$monographFiles)
{
$filesDir = MonographFileManager::_getFilesDir($monographId);
$filePaths = array();
while ($monographFile =& $monographFiles->next()) {
/* @var $monographFile MonographFile */
// Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path)
$filePath = str_replace($filesDir, '', $monographFile->getFilePath());
// Add files to be archived to array
$filePaths[] = escapeshellarg($filePath);
}
// Create the archive and download the file
$archivePath = $filesDir . "monograph_" . $monographId . "_files.tar.gz";
$tarCommand = "tar czf " . $archivePath . " -C \"" . $filesDir . "\" " . implode(" ", $filePaths);
exec($tarCommand);
if (file_exists($archivePath)) {
parent::downloadFile($archivePath);
return true;
} else {
return false;
}
}
示例10: downloadFile
/**
* Download a file.
* @param $fileId int the file id of the file to download
* @param $revision int the revision of the file to download
* @param $inline print file as inline instead of attachment, optional
* @return boolean
*/
function downloadFile($fileId, $revision = null, $inline = false)
{
$articleFile =& $this->getFile($fileId, $revision);
if (isset($articleFile)) {
$fileType = $articleFile->getFileType();
$filePath = $this->filesDir . $this->fileStageToPath($articleFile->getFileStage()) . '/' . $articleFile->getFileName();
return parent::downloadFile($filePath, $fileType, $inline);
} else {
return false;
}
}
示例11: display
/**
* Display the plugin.
* @param $args array
* @param $request PKPRequest
*/
function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$press = $request->getPress();
parent::display($args, $request);
$templateMgr->assign('plugin', $this);
switch (array_shift($args)) {
case 'index':
case '':
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
break;
case 'uploadImportXML':
$user = $request->getUser();
import('lib.pkp.classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
if ($temporaryFile) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId()));
} else {
$json = new JSONMessage(false, __('common.uploadFailed'));
}
return $json->getString();
case 'importBounce':
$json = new JSONMessage(true);
$json->setEvent('addTab', array('title' => __('plugins.importexport.native.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId')))));
return $json->getString();
case 'import':
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
$temporaryFileId = $request->getUserVar('temporaryFileId');
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
$user = $request->getUser();
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
if (!$temporaryFile) {
$json = new JSONMessage(true, __('plugins.inportexport.native.uploadFile'));
return $json->getString();
}
$temporaryFilePath = $temporaryFile->getFilePath();
$deployment = new NativeImportExportDeployment($press, $user);
libxml_use_internal_errors(true);
$submissions = $this->importSubmissions(file_get_contents($temporaryFilePath), $deployment);
$templateMgr->assign('submissions', $submissions);
$validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;'));
$templateMgr->assign('validationErrors', $validationErrors);
libxml_clear_errors();
// Are there any submissions import errors
$processedSubmissionsIds = $deployment->getProcessedObjectsIds(ASSOC_TYPE_SUBMISSION);
if (!empty($processedSubmissionsIds)) {
$submissionsErrors = array_filter($processedSubmissionsIds, create_function('$a', 'return !empty($a);'));
if (!empty($submissionsErrors)) {
$templateMgr->assign('submissionsErrors', $processedSubmissionsIds);
}
}
// If there are any submissions or validataion errors
// delete imported submissions.
if (!empty($submissionsErrors) || !empty($validationErrors)) {
// remove all imported sumissions
$deployment->removeImportedObjects(ASSOC_TYPE_SUBMISSION);
}
// Display the results
$json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl'));
return $json->getString();
case 'export':
$exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser());
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
}
}
示例12: downloadAllFiles
/**
* Download all of the monograph files as one compressed file.
* @param $args array
* @param $request Request
*/
function downloadAllFiles($args, &$request)
{
// Retrieve the monograph.
$monograph =& $this->getMonograph();
$monographId = $monograph->getId();
// Find out the paths of all files in this grid.
import('classes.file.MonographFileManager');
$filesDir = MonographFileManager::_getFilesDir($monographId);
$filePaths = array();
foreach ($this->getGridDataElements($request) as $submissionFileData) {
$monographFile =& $submissionFileData['submissionFile'];
/* @var $monographFile MonographFile */
// Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path)
$filePath = str_replace($filesDir, '', $monographFile->getFilePath());
// Add files to be archived to array
$filePaths[] = escapeshellarg($filePath);
unset($monographFile);
}
// Create a temporary file.
$archivePath = tempnam('/tmp', 'sf-');
// Create the archive and download the file.
exec(Config::getVar('cli', 'tar') . ' -c -z ' . '-f ' . escapeshellarg($archivePath) . ' ' . '-C ' . escapeshellarg($filesDir) . ' ' . implode(' ', array_map('escapeshellarg', $filePaths)));
if (file_exists($archivePath)) {
FileManager::downloadFile($archivePath);
FileManager::deleteFile($archivePath);
} else {
fatalError('Creating archive with submission files failed!');
}
}
示例13: downloadAllFiles
/**
* Download all passed files.
* @param $args array
* @param $request Request
*/
function downloadAllFiles($args, $request)
{
// Retrieve the authorized objects.
$submissionFiles = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILES);
$submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
// Find out the paths of all files in this grid.
$context = $request->getContext();
$filePaths = array();
$fileManager = $this->_getFileManager($context->getId(), $submission->getId());
$filesDir = $fileManager->getBasePath();
foreach ($submissionFiles as $submissionFile) {
// Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path)
$filePaths[str_replace($filesDir, '', $submissionFile->getFilePath())] = $submissionFile->getClientFileName();
}
import('lib.pkp.classes.file.FileArchive');
$fileArchive = new FileArchive();
$archivePath = $fileArchive->create($filePaths, $filesDir);
if (file_exists($archivePath)) {
$fileManager = new FileManager();
if ($fileArchive->zipFunctional()) {
$fileManager->downloadFile($archivePath, 'application/x-zip', false, 'files.zip');
} else {
$fileManager->downloadFile($archivePath, 'application/x-gtar', false, 'files.tar.gz');
}
$fileManager->deleteFile($archivePath);
} else {
fatalError('Creating archive with submission files failed!');
}
}
示例14: display
/**
* Display the plugin.
* @param $args array
* @param $request PKPRequest
*/
function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$context = $request->getContext();
parent::display($args, $request);
$templateMgr->assign('plugin', $this);
switch (array_shift($args)) {
case 'index':
case '':
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
break;
case 'uploadImportXML':
$user = $request->getUser();
import('lib.pkp.classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
if ($temporaryFile) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId()));
} else {
$json = new JSONMessage(false, __('common.uploadFailed'));
}
return $json->getString();
case 'importBounce':
$json = new JSONMessage(true);
$json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId')))));
return $json->getString();
case 'import':
$temporaryFileId = $request->getUserVar('temporaryFileId');
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
$user = $request->getUser();
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
if (!$temporaryFile) {
$json = new JSONMessage(true, __('plugins.importexport.users.uploadFile'));
return $json->getString();
}
$temporaryFilePath = $temporaryFile->getFilePath();
libxml_use_internal_errors(true);
$users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user);
$validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;'));
$templateMgr->assign('validationErrors', $validationErrors);
libxml_clear_errors();
$templateMgr->assign('users', $users);
$json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl'));
return $json->getString();
case 'export':
$exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser());
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
case 'exportAllUsers':
$exportXml = $this->exportAllUsers($request->getContext(), $request->getUser());
import('lib.pkp.classes.file.TemporaryFileManager');
$fileManager = new TemporaryFileManager();
$exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$fileManager->downloadFile($exportFileName);
$fileManager->deleteFile($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
}
}
示例15: downloadFile
/**
* Download a file.
* @param $fileId int the file id of the file to download
* @param $revision int the revision of the file to download
* @param $inline print file as inline instead of attachment, optional
* @return boolean
*/
function downloadFile($monographId, $fileId, $revision = null, $inline = false)
{
$returner = false;
$monographFile =& MonographFileManager::_getFile($fileId, $revision);
if (isset($monographFile)) {
// Make sure that the file belongs to the monograph.
if ($monographFile->getMonographId() != $monographId) {
fatalError('Invalid file id!');
}
// Mark the file as viewed by this user.
$sessionManager =& SessionManager::getManager();
$session =& $sessionManager->getUserSession();
$user =& $session->getUser();
if (is_a($user, 'User')) {
$viewsDao =& DAORegistry::getDAO('ViewsDAO');
$viewsDao->recordView(ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileIdAndRevision(), $user->getId());
}
// Send the file to the user.
$filePath = $monographFile->getFilePath();
$mediaType = $monographFile->getFileType();
$returner = parent::downloadFile($filePath, $mediaType, $inline);
}
return $returner;
}