Skip to content

Commit 73cb158

Browse files
committed
完善上传类对附件上传的表单名称的记录
1 parent 26083d5 commit 73cb158

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

Extend/Library/ORG/Net/UploadFile.class.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ private function save($file) {
105105
if(false !== $image) {
106106
//是图像文件生成缩略图
107107
$thumbWidth = explode(',',$this->thumbMaxWidth);
108-
$thumbHeight = explode(',',$this->thumbMaxHeight);
109-
$thumbPrefix = explode(',',$this->thumbPrefix);
110-
$thumbSuffix = explode(',',$this->thumbSuffix);
111-
$thumbFile = explode(',',$this->thumbFile);
112-
$thumbPath = $this->thumbPath?$this->thumbPath:dirname($filename).'/';
108+
$thumbHeight = explode(',',$this->thumbMaxHeight);
109+
$thumbPrefix = explode(',',$this->thumbPrefix);
110+
$thumbSuffix = explode(',',$this->thumbSuffix);
111+
$thumbFile = explode(',',$this->thumbFile);
112+
$thumbPath = $this->thumbPath?$this->thumbPath:dirname($filename).'/';
113113
// 生成图像缩略图
114114
import($this->imageClassPath);
115115
for($i=0,$len=count($thumbWidth); $i<$len; $i++) {
116116
if(!empty($thumbFile[$i])) {
117117
$thumbname = $thumbFile[$i];
118118
}else{
119-
$prefix = isset($thumbPrefix[$i])?$thumbPrefix[$i]:$thumbPrefix[0];
120-
$suffix = isset($thumbSuffix[$i])?$thumbSuffix[$i]:$thumbSuffix[0];
119+
$prefix = isset($thumbPrefix[$i])?$thumbPrefix[$i]:$thumbPrefix[0];
120+
$suffix = isset($thumbSuffix[$i])?$thumbSuffix[$i]:$thumbSuffix[0];
121121
$thumbname = $prefix.basename($filename,'.'.$file['extension']).$suffix;
122122
}
123123
Image::thumb($filename,$thumbPath.$thumbname.'.'.$file['extension'],'',$thumbWidth[$i],$thumbHeight[$i],true);
@@ -163,7 +163,7 @@ public function upload($savePath ='') {
163163
return false;
164164
}
165165
}
166-
$fileInfo = array();
166+
$fileInfo = array();
167167
$isUpload = false;
168168

169169
// 获取上传的文件信息
@@ -173,10 +173,10 @@ public function upload($savePath ='') {
173173
//过滤无效的上传
174174
if(!empty($file['name'])) {
175175
//登记上传文件的扩展信息
176-
$file['key'] = $key;
177-
$file['extension'] = $this->getExt($file['name']);
178-
$file['savepath'] = $savePath;
179-
$file['savename'] = $this->getSaveName($file);
176+
if(!isset($file['key'])) $file['key'] = $key;
177+
$file['extension'] = $this->getExt($file['name']);
178+
$file['savepath'] = $savePath;
179+
$file['savename'] = $this->getSaveName($file);
180180

181181
// 自动检查附件
182182
if($this->autoCheck) {
@@ -277,22 +277,23 @@ public function uploadOne($file,$savePath=''){
277277
* @return array
278278
*/
279279
private function dealFiles($files) {
280-
$fileArray = array();
281-
$n = 0;
282-
foreach ($files as $file){
283-
if(is_array($file['name'])) {
284-
$keys = array_keys($file);
285-
$count = count($file['name']);
286-
for ($i=0; $i<$count; $i++) {
287-
foreach ($keys as $key)
288-
$fileArray[$n][$key] = $file[$key][$i];
289-
$n++;
290-
}
291-
}else{
292-
$fileArray[$n] = $file;
293-
$n++;
294-
}
295-
}
280+
$fileArray = array();
281+
$n = 0;
282+
foreach ($files as $key=>$file){
283+
if(is_array($file['name'])) {
284+
$keys = array_keys($file);
285+
$count = count($file['name']);
286+
for ($i=0; $i<$count; $i++) {
287+
$fileArray[$n]['key'] = $key;
288+
foreach ($keys as $_key){
289+
$fileArray[$n][$_key] = $file[$_key][$i];
290+
}
291+
$n++;
292+
}
293+
}else{
294+
$fileArray[$key] = $file;
295+
}
296+
}
296297
return $fileArray;
297298
}
298299

@@ -364,12 +365,12 @@ private function getSaveName($filename) {
364365
private function getSubName($file) {
365366
switch($this->subType) {
366367
case 'date':
367-
$dir = date($this->dateFormat,time()).'/';
368+
$dir = date($this->dateFormat,time()).'/';
368369
break;
369370
case 'hash':
370371
default:
371-
$name = md5($file['savename']);
372-
$dir = '';
372+
$name = md5($file['savename']);
373+
$dir = '';
373374
for($i=0;$i<$this->hashLevel;$i++) {
374375
$dir .= $name{$i}.'/';
375376
}
@@ -422,8 +423,8 @@ private function check($file) {
422423

423424
// 自动转换字符集 支持数组转换
424425
private function autoCharset($fContents, $from='gbk', $to='utf-8') {
425-
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
426-
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
426+
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
427+
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
427428
if (strtoupper($from) === strtoupper($to) || empty($fContents) || (is_scalar($fContents) && !is_string($fContents))) {
428429
//如果编码相同或者非字符串标量则不转换
429430
return $fContents;

0 commit comments

Comments
 (0)