* finish task #2055.
This commit is contained in:
@@ -48,6 +48,7 @@ class file extends control
|
||||
$file = $file[0];
|
||||
if($file)
|
||||
{
|
||||
if($file['size'] == 0) die(json_encode(array('error' => 1, 'message' => $this->lang->file->errorFileUpload)));
|
||||
if(@move_uploaded_file($file['tmpname'], $this->file->savePath . $file['pathname']))
|
||||
{
|
||||
$url = $this->file->webPath . $file['pathname'];
|
||||
|
||||
@@ -23,3 +23,5 @@ $lang->file->maxUploadSize = "<span class='red'>%s</span>";
|
||||
$lang->file->errorNotExists = "<span class='red'>The directory '%s' is no exist</span>";
|
||||
$lang->file->errorCanNotWrite = "<span class='red'>The directory '%s' is unwritable, please change it's permission. Command in linux:sudo -R chmod 777 '%s'</span>";
|
||||
$lang->file->confirmDelete = " Are you sure to delete this file?";
|
||||
$lang->file->errorFileSize = " The file size exceeds the limit, might not be able to upload!";
|
||||
$lang->file->errorFileUpload = " Failed to upload files, file size may exceed the limit!";
|
||||
|
||||
@@ -23,3 +23,5 @@ $lang->file->maxUploadSize = "<span class='red'>%s</span>";
|
||||
$lang->file->errorNotExists = "<span class='red'>文件夹 '%s' 不存在</span>";
|
||||
$lang->file->errorCanNotWrite = "<span class='red'>文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令:sudo chmod -R 777 '%s'</span>";
|
||||
$lang->file->confirmDelete = " 您确定删除该附件吗?";
|
||||
$lang->file->errorFileSize = " 文件大小已经超过限制,可能不能成功上传!";
|
||||
$lang->file->errorFileUpload = " 文件上传失败,文件大小可能超出限制";
|
||||
|
||||
@@ -76,6 +76,7 @@ class fileModel extends model
|
||||
|
||||
foreach($files as $id => $file)
|
||||
{
|
||||
if($file['size'] == 0) continue;
|
||||
move_uploaded_file($file['tmpname'], $this->savePath . $file['pathname']);
|
||||
$file['objectType'] = $objectType;
|
||||
$file['objectID'] = $objectID;
|
||||
|
||||
@@ -11,7 +11,7 @@ table.fileBox td {padding: 0!important}
|
||||
$fileRow = <<<EOT
|
||||
<table class='fileBox' id='fileBox\$i'>
|
||||
<tr>
|
||||
<td class='w-p45'><div class='form-control file-wrapper'><input type='file' name='files[]' class='fileControl' tabindex='-1' /></div></td>
|
||||
<td class='w-p45'><div class='form-control file-wrapper'><input type='file' name='files[]' class='fileControl' tabindex='-1' onchange='checkSize(this)'/></div></td>
|
||||
<td class=''><input type='text' name='labels[]' class='form-control' placeholder='{$lang->file->label}' tabindex='-1' /></td>
|
||||
<td class='w-30px'><a href='javascript:void();' onclick='addFile(this)' class='btn btn-block'><i class='icon-plus'></i></a></td>
|
||||
<td class='w-30px'><a href='javascript:void();' onclick='delFile(this)' class='btn btn-block'><i class='icon-remove'></i></a></td>
|
||||
@@ -37,6 +37,26 @@ $(function()
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Check file size.
|
||||
*
|
||||
* @param obj $obj
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function checkSize(obj)
|
||||
{
|
||||
if(typeof($(obj)[0].files) != 'undefined')
|
||||
{
|
||||
var maxUploadInfo = '<?php echo strtoupper(ini_get('upload_max_filesize'));?>';
|
||||
var sizeType = {'K': 1024, 'M': 1024 * 1024, 'G': 1024 * 1024 * 1024};
|
||||
var unit = maxUploadInfo.replace(/\d+/, '');
|
||||
var maxUploadSize = maxUploadInfo.replace(unit,'') * sizeType[unit];
|
||||
var fileSize = $(obj)[0].files[0].size;
|
||||
if(fileSize > maxUploadSize) alert('<?php echo $lang->file->errorFileSize?>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the upload max filesize of config.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user