本文整理汇总了PHP中Jaws_Utils::Download方法的典型用法代码示例。如果您正苦于以下问题:PHP Jaws_Utils::Download方法的具体用法?PHP Jaws_Utils::Download怎么用?PHP Jaws_Utils::Download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jaws_Utils
的用法示例。
在下文中一共展示了Jaws_Utils::Download方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Attachment
/**
* Download post attachment
*
* @access public
* @return string Requested file content or HTML error page
*/
function Attachment()
{
$rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'attach'), 'get');
$pModel = $this->gadget->model->load('Posts');
$post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']);
if (Jaws_Error::IsError($post)) {
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
$aModel = $this->gadget->model->load('Attachments');
$attachment = $aModel->GetAttachmentInfo($rqst['attach']);
if (Jaws_Error::IsError($attachment)) {
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
if (!empty($attachment)) {
$filepath = JAWS_DATA . 'forums/' . $attachment['filename'];
if (file_exists($filepath)) {
// increase download hits
$result = $aModel->HitAttachmentDownload($rqst['attach']);
if (Jaws_Error::IsError($result)) {
// do nothing
}
if (Jaws_Utils::Download($filepath, $attachment['title'])) {
return;
}
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
}
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(404);
}
示例2: Attachment
/**
* Download message attachment
*
* @access public
* @return string Requested file content or HTML error page
*/
function Attachment()
{
if (!$GLOBALS['app']->Session->Logged()) {
return Jaws_HTTPError::Get(401);
}
$rqst = jaws()->request->fetch(array('uid', 'mid', 'aid'), 'get');
$user = $GLOBALS['app']->Session->GetAttribute('user');
$mModel = $this->gadget->model->load('Message');
$aModel = $this->gadget->model->load('Attachment');
$message = $mModel->GetMessage($rqst['mid'], false, false);
if (Jaws_Error::IsError($message)) {
return Jaws_HTTPError::Get(500);
}
// Check permissions
if (!($message['from'] == $user && $message['to'] == 0) && $message['to'] != $user || $user != $rqst['uid']) {
return Jaws_HTTPError::Get(403);
}
$attachment = $aModel->GetAttachment($rqst['aid'], $rqst['mid']);
if (!empty($attachment)) {
$filepath = JAWS_DATA . 'pm' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $attachment['filename'];
if (file_exists($filepath)) {
if (Jaws_Utils::Download($filepath, $attachment['title'], $attachment['filetype'])) {
return;
}
return Jaws_HTTPError::Get(500);
}
}
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(404);
}
示例3: Export
/**
* Export language
*
* @access public
* @return void
*/
function Export()
{
$lang = jaws()->request->fetch('lang', 'get');
require_once PEAR_PATH . 'File/Archive.php';
$tmpDir = sys_get_temp_dir();
$tmpFileName = "{$lang}.tar";
$tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName;
$writerObj = File_Archive::toFiles();
$src = File_Archive::read(JAWS_DATA . "languages/{$lang}", $lang);
$dst = File_Archive::toArchive($tmpArchiveName, $writerObj);
$res = File_Archive::extract($src, $dst);
if (!PEAR::isError($res)) {
return Jaws_Utils::Download($tmpArchiveName, $tmpFileName);
}
Jaws_Header::Referrer();
}
示例4: ExportLogs
/**
* Export Logs
*
* @access public
* @return void
*/
function ExportLogs()
{
$this->gadget->CheckPermission('ExportLogs');
$filters = jaws()->request->fetch(array('from_date', 'to_date', 'gname', 'user', 'priority', 'status'), 'get');
$filters['gadget'] = $filters['gname'];
unset($filters['gname']);
$model = $this->gadget->model->load('Logs');
$logs = $model->GetLogs($filters);
if (Jaws_Error::IsError($logs) || count($logs) < 1) {
return;
}
$tmpDir = sys_get_temp_dir();
$tmpCSVFileName = uniqid(rand(), true) . '.csv';
$fp = fopen($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName, 'w');
$date = Jaws_Date::getInstance();
foreach ($logs as $log) {
$exportData = '';
$exportData .= $log['id'] . ',';
$exportData .= $log['username'] . ',';
$exportData .= $log['gadget'] . ',';
$exportData .= $log['action'] . ',';
$exportData .= $log['priority'] . ',';
$exportData .= $log['apptype'] . ',';
$exportData .= $log['backend'] . ',';
$exportData .= long2ip($log['ip']) . ',';
$exportData .= $log['status'] . ',';
$exportData .= $date->Format($log['insert_time'], 'Y-m-d H:i:s');
$exportData .= PHP_EOL;
fwrite($fp, $exportData);
}
fclose($fp);
require_once PEAR_PATH . 'File/Archive.php';
$tmpFileName = uniqid(rand(), true) . '.tar.gz';
$tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName;
$writerObj = File_Archive::toFiles();
$src = File_Archive::read($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName);
$dst = File_Archive::toArchive($tmpArchiveName, $writerObj);
$res = File_Archive::extract($src, $dst);
if (!PEAR::isError($res)) {
return Jaws_Utils::Download($tmpArchiveName, $tmpFileName);
}
Jaws_Header::Referrer();
}
示例5: DownloadTheme
/**
* Downloads the theme
*
* @access public
* @returns void
*/
function DownloadTheme()
{
$theme = jaws()->request->fetch('theme', 'get');
@(list($theme, $locality) = explode(',', $theme));
$tInfo = Jaws_Utils::GetThemesInfo($locality, $theme);
if (!empty($tInfo)) {
if (!$tInfo['download']) {
return Jaws_HTTPError::Get(403);
}
$tmpDir = sys_get_temp_dir();
$tmsModel = $this->gadget->model->loadAdmin('Themes');
$res = $tmsModel->packTheme($tInfo['name'], ($locality == 0 ? JAWS_DATA : JAWS_BASE_DATA) . 'themes', $tmpDir, false);
if (!Jaws_Error::isError($res)) {
Jaws_Utils::Download($res, "{$theme}.zip");
return;
}
} else {
return Jaws_HTTPError::Get(404);
}
}
示例6: Download
/**
* Action for providing download file
*
* @access public
* @return string Requested file content or HTML error page
*/
function Download()
{
$id = jaws()->request->fetch('id', 'get');
$id = Jaws_XSS::defilter($id);
$fModel = $this->gadget->model->load('Files');
$iFile = $fModel->DBFileInfoByIndex($id);
if (Jaws_Error::IsError($iFile)) {
$this->SetActionMode('Download', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
if (!empty($iFile)) {
$filepath = $fModel->GetFileBrowserRootDir() . $iFile['path'] . '/' . $iFile['filename'];
if (file_exists($filepath)) {
// increase download hits
$fModel->HitFileDownload($iFile['id']);
if (Jaws_Utils::Download($filepath, $iFile['filename'])) {
return;
}
$this->SetActionMode('Download', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
}
$this->SetActionMode('Download', 'normal', 'standalone');
return Jaws_HTTPError::Get(404);
}
示例7: Download
/**
* Downloads(streams) file
*
* @access public
* @return mixed File data or Jaws_Error
*/
function Download()
{
$id = jaws()->request->fetch('id');
if (is_null($id)) {
return Jaws_HTTPError::Get(500);
}
$id = (int) $id;
$model = $this->gadget->model->loadAdmin('Files');
// Validate file
$file = $model->GetFile($id);
if (Jaws_Error::IsError($file)) {
return Jaws_HTTPError::Get(500);
}
if (empty($file) || empty($file['user_filename'])) {
return Jaws_HTTPError::Get(404);
}
// Check for file existence
$filename = $GLOBALS['app']->getDataURL("directory/") . $file['host_filename'];
if (!file_exists($filename)) {
return Jaws_HTTPError::Get(404);
}
// Stream file
if (!Jaws_Utils::Download($filename, $file['user_filename'], $file['filetype'])) {
return Jaws_HTTPError::Get(500);
}
return true;
}
示例8: Download
/**
* Downloads file (stream)
*
* @access public
* @return mixed File data or Jaws_Error
*/
function Download($open = true)
{
$id = jaws()->request->fetch('id');
if (is_null($id)) {
return Jaws_HTTPError::Get(500);
}
$id = (int) $id;
$model = $this->gadget->model->load('Files');
// Validate file
$file = $model->GetFile($id);
if (Jaws_Error::IsError($file)) {
return Jaws_HTTPError::Get(500);
}
if (empty($file) || empty($file['filename'])) {
return Jaws_HTTPError::Get(404);
}
// Validate user
if (!$file['public']) {
$user = (int) $GLOBALS['app']->Session->GetAttribute('user');
$access = $model->CheckAccess($id, $user);
if ($access !== true) {
return Jaws_HTTPError::Get(403);
}
}
// Check for file existance
$uid = $file['id'] == $file['reference'] ? $file['user'] : $file['owner'];
$filename = $GLOBALS['app']->getDataURL("directory/{$uid}/") . $file['filename'];
if (!file_exists($filename)) {
return Jaws_HTTPError::Get(404);
}
// Stream file
if (!Jaws_Utils::Download($filename, $file['filename'], $file['filetype'], $open)) {
return Jaws_HTTPError::Get(500);
}
return;
}