* finish task #2883.
This commit is contained in:
@@ -7,6 +7,8 @@ $config->file->mimes['default'] = 'application/octet-stream';
|
||||
$config->file->imageExtensions = array('jpeg', 'jpg', 'gif', 'png');
|
||||
$config->file->image2Compress = array('.jpg', '.bmp', '.jpeg');
|
||||
|
||||
$config->file->charset = array('UTF-8' => 'UTF-8', 'GBK' => 'GBK', 'BIG5' => 'BIG5');
|
||||
|
||||
$config->file->ueditor["imageActionName"] = "uploadimage";
|
||||
$config->file->ueditor["imageFieldName"] = "upfile";
|
||||
$config->file->ueditor["imageMaxSize"] = 2048000;
|
||||
|
||||
+22
-13
@@ -133,25 +133,34 @@ class file extends control
|
||||
$fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html';
|
||||
if(stripos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open';
|
||||
|
||||
/* If the mode is open, locate directly. */
|
||||
if($mode == 'open')
|
||||
if(file_exists($file->realPath))
|
||||
{
|
||||
if(file_exists($file->realPath))$this->locate($file->webPath);
|
||||
$this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Down the file. */
|
||||
if(file_exists($file->realPath))
|
||||
/* If the mode is open, locate directly. */
|
||||
if($mode == 'open')
|
||||
{
|
||||
if(stripos('txt|jpg|jpeg|gif|png|bmp', $file->extension) !== false)
|
||||
{
|
||||
$this->view->file = $file;
|
||||
$this->view->charset = $this->get->charset ? $this->get->charset : $this->config->charset;
|
||||
$this->view->fileType = ($file->extension == 'txt') ? 'txt' : 'image';
|
||||
$this->display();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->locate($file->webPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Down the file. */
|
||||
$fileName = $file->title . '.' . $file->extension;
|
||||
$fileData = file_get_contents($file->realPath);
|
||||
$this->sendDownHeader($fileName, $file->extension, $fileData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ $lang->file->setPublic = "Set Public Template";
|
||||
$lang->file->exportFields = "Fileds to be Exported";
|
||||
$lang->file->defaultTPL = "Default Template";
|
||||
$lang->file->setExportTPL = "Settings";
|
||||
$lang->file->preview = "Preview";
|
||||
|
||||
$lang->file->errorNotExists = "<span class='red'>'%s' is not found.</span>";
|
||||
$lang->file->errorCanNotWrite = "<span class='red'>'%s' is not writable. Please change its permission. Enter sudo chmod -R 777 '%s'</span> in Linux.";
|
||||
|
||||
@@ -25,6 +25,7 @@ $lang->file->setPublic = "设置公共模板";
|
||||
$lang->file->exportFields = "要导出字段";
|
||||
$lang->file->defaultTPL = "默认模板";
|
||||
$lang->file->setExportTPL = "设置";
|
||||
$lang->file->preview = "预览";
|
||||
|
||||
$lang->file->errorNotExists = "<span class='red'>文件夹 '%s' 不存在</span>";
|
||||
$lang->file->errorCanNotWrite = "<span class='red'>文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令:sudo chmod -R 777 '%s'</span>";
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php include '../../common/view/header.lite.html.php';?>
|
||||
<?php js::set('fileID', $file->id);?>
|
||||
<style>
|
||||
#imageFile{text-align: center;}
|
||||
#imageFile img{margin: 10px auto;}
|
||||
#txtFile{overflow-x: auto; padding: 0 7px;}
|
||||
#titlebar span{float: right; padding-right: 25px;}
|
||||
</style>
|
||||
<div id='titlebar'>
|
||||
<div class='heading'>
|
||||
<strong><?php echo $lang->file->common;?></strong>
|
||||
<small class='text-muted'><?php echo $lang->file->preview;?></small>
|
||||
<?php if($fileType == 'txt'):?>
|
||||
<span><?php echo html::select('charset', $config->file->charset, $charset, "onchange='setCharset(this.value)'");?></span>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if($fileType == 'image'):?>
|
||||
<div id='imageFile'>
|
||||
<?php echo html::image($file->webPath);?>
|
||||
</div>
|
||||
<?php else:?>
|
||||
<div id='txtFile'>
|
||||
<?php
|
||||
$fileContent = file_get_contents($file->realPath);
|
||||
if($charset != $config->charset)
|
||||
{
|
||||
$fileContent = helper::convertEncoding($fileContent, $charset, $config->charset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!extension_loaded('mbstring'))
|
||||
{
|
||||
$encoding = mb_detect_encoding($fileContent, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
|
||||
if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($config->default->lang == 'zh-cn') $encoding = 'GBK';
|
||||
if($config->default->lang == 'zh-tw') $encoding = 'BIG5';
|
||||
$fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset);
|
||||
}
|
||||
}
|
||||
a($fileContent);
|
||||
?>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<script>
|
||||
function setCharset(charset)
|
||||
{
|
||||
var param = (config.requestType == 'PATH_INFO' ? '?' : '&') + 'charset=' + charset;
|
||||
var link = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left') + param;
|
||||
location.href = link;
|
||||
}
|
||||
</script>
|
||||
<?php include '../../common/view/footer.lite.html.php';?>
|
||||
@@ -15,12 +15,20 @@ function deleteFile(fileID)
|
||||
hiddenwin.location.href =createLink('file', 'delete', 'fileID=' + fileID);
|
||||
}
|
||||
/* Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it. */
|
||||
function downloadFile(fileID)
|
||||
function downloadFile(fileID, extension)
|
||||
{
|
||||
if(!fileID) return;
|
||||
var fileTypes = 'txt,jpg,jpeg,gif,png,bmp';
|
||||
var sessionString = '<?php echo $sessionString;?>';
|
||||
var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left') + sessionString;
|
||||
window.open(url, '_blank');
|
||||
var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left') + sessionString;
|
||||
if(fileTypes.indexOf(extension) >= 0)
|
||||
{
|
||||
$('<a>').modalTrigger({url: url, type: 'iframe'}).trigger('click');
|
||||
}
|
||||
else
|
||||
{
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
@@ -36,7 +44,7 @@ function downloadFile(fileID)
|
||||
{
|
||||
$uploadDate = $lang->file->uploadDate . $file->addedDate;
|
||||
$fileTitle = "<li title={$uploadDate} class='list-group-item'><i class='icon-file-text text-muted icon'></i> " . $file->title .'.' . $file->extension;
|
||||
echo html::a($this->createLink('file', 'download', "fileID=$file->id") . $sessionString, $fileTitle, '_blank', "onclick='return downloadFile($file->id)'");
|
||||
echo html::a($this->createLink('file', 'download', "fileID=$file->id") . $sessionString, $fileTitle, '_blank', "onclick=\"return downloadFile($file->id, '$file->extension')\"");
|
||||
|
||||
/* Show size info. */
|
||||
if($file->size < 1024)
|
||||
|
||||
Reference in New Issue
Block a user