Esempio n. 1
0
 /**
  * @brief  开始执行上传
  * @return array 包含上传成功信息的数组
  *		$file = array(
  *			 name    如果上传成功,则返回上传后的文件名称,如果失败,则返回客户端名称
  *			 size    上传附件大小
  *           fileSrc 上传文件完整路径
  *			 dir     上传目录
  *			 ininame 上传图片名
  *			 flag    -1:文件类型不允许; -2:文件大小超出限制; 1:上传成功
  *			 ext     上传附件扩展名
  *		);
  */
 public function execute()
 {
     //总的文件上传信息
     $info = array();
     foreach ($_FILES as $field => $file) {
         $fileInfo = array();
         //不存在上传的文件名
         if (!isset($_FILES[$field]['name']) || $_FILES[$field]['name'] == '' || !isset($_FILES[$field]['tmp_name'])) {
             continue;
         }
         //上传控件为数组格式 file[]格式
         if (is_array($_FILES[$field]['name'])) {
             $keys = array_keys($_FILES[$field]['name']);
             foreach ($keys as $key) {
                 if (!isset($_FILES[$field]['name'][$key]) || $_FILES[$field]['name'][$key] == '') {
                     continue;
                 }
                 //获取扩展名
                 $fileext = IFile::getFileType($_FILES[$field]['tmp_name'][$key]);
                 if (is_array($fileext) || $fileext == null) {
                     $fileext = IFile::getFileSuffix($_FILES[$field]['name'][$key]);
                 }
                 /*开始上传文件*/
                 //(1)上传类型不符合
                 if (!in_array($fileext, $this->allowType)) {
                     $fileInfo[$key]['name'] = $_FILES[$field]['name'][$key];
                     $fileInfo[$key]['flag'] = -1;
                 } else {
                     if ($_FILES[$field]['size'][$key] > $this->maxsize) {
                         $fileInfo[$key]['name'] = $_FILES[$field]['name'][$key];
                         $fileInfo[$key]['flag'] = -2;
                     } else {
                         //修改图片状态值
                         $fileInfo[$key]['name'] = ITime::getDateTime('Ymdhis') . mt_rand(100, 999) . '.' . $fileext;
                         $fileInfo[$key]['dir'] = $this->dir;
                         $fileInfo[$key]['size'] = $_FILES[$field]['size'][$key];
                         $fileInfo[$key]['ininame'] = $_FILES[$field]['name'][$key];
                         $fileInfo[$key]['ext'] = $fileext;
                         $fileInfo[$key]['fileSrc'] = $fileInfo[$key]['dir'] . $fileInfo[$key]['name'];
                         if (is_uploaded_file($_FILES[$field]['tmp_name'][$key])) {
                             if (move_uploaded_file($_FILES[$field]['tmp_name'][$key], $this->dir . $fileInfo[$key]['name'])) {
                                 if (file_exists($_FILES[$field]['tmp_name'][$key])) {
                                     IFile::unlink($_FILES[$field]['tmp_name'][$key]);
                                 }
                                 $fileInfo[$key]['flag'] = 1;
                             }
                         }
                     }
                 }
             }
         } else {
             if ($_FILES[$field]['name'] == '' || $_FILES[$field]['tmp_name'] == '') {
                 continue;
             }
             //获取扩展名
             $fileext = IFile::getFileType($_FILES[$field]['tmp_name']);
             if (is_array($fileext) || $fileext == null) {
                 $fileext = IFile::getFileSuffix($_FILES[$field]['name']);
             }
             /*开始上传文件*/
             //(1)上传类型不符合
             if (!in_array($fileext, $this->allowType)) {
                 $fileInfo[0]['name'] = $_FILES[$field]['name'];
                 $fileInfo[0]['flag'] = -1;
             } else {
                 if ($_FILES[$field]['size'] > $this->maxsize) {
                     $fileInfo[0]['name'] = $_FILES[$field]['name'];
                     $fileInfo[0]['flag'] = -2;
                 } else {
                     //修改图片状态值
                     $fileInfo[0]['name'] = ITime::getDateTime('Ymdhis') . mt_rand(100, 999) . '.' . $fileext;
                     $fileInfo[0]['dir'] = $this->dir;
                     $fileInfo[0]['size'] = $_FILES[$field]['size'];
                     $fileInfo[0]['ininame'] = $_FILES[$field]['name'];
                     $fileInfo[0]['ext'] = $fileext;
                     $fileInfo[0]['fileSrc'] = $fileInfo[0]['dir'] . $fileInfo[0]['name'];
                     if (is_uploaded_file($_FILES[$field]['tmp_name'])) {
                         if (move_uploaded_file($_FILES[$field]['tmp_name'], $this->dir . $fileInfo[0]['name'])) {
                             if (file_exists($_FILES[$field]['tmp_name'])) {
                                 IFile::unlink($_FILES[$field]['tmp_name']);
                             }
                             $fileInfo[0]['flag'] = 1;
                         }
                     }
                 }
             }
         }
         $info[$field] = $fileInfo;
     }
     return $info;
 }
Esempio n. 2
0
 /**
  * @brief  开始执行上传
  * @return array 包含上传成功信息的数组
  *		$file = array(
  *			 name    如果上传成功,则返回上传后的文件名称,如果失败,则返回客户端名称
  *			 size    上传附件大小
  *           fileSrc 上传文件完整路径
  *			 dir     上传目录
  *			 ininame 上传图片名
  *			 flag    -1:上传的文件超出服务器限制; -2:上传的文件超出浏览器限制; -3:上传的文件被部分上传; -4:没有找到上传的文件; -5:上传的文件丢失;
  *                   -6:上传的临时文件没有正确写入; -7:扩展名不允许上传; -8:上传的文件超出了程序的限制; -9:上传的文件中有木马病毒 ; 1:上传成功;
  *			 ext     上传附件扩展名
  *		);
  */
 public function execute()
 {
     //总的文件上传信息
     $info = array();
     foreach ($_FILES as $field => $file) {
         $fileInfo = array();
         //不存在上传的文件名
         if (!isset($_FILES[$field]['name']) || $_FILES[$field]['name'] == '') {
             continue;
         }
         //上传控件为数组格式 file[]格式
         if (is_array($_FILES[$field]['name'])) {
             $keys = array_keys($_FILES[$field]['name']);
             foreach ($keys as $key) {
                 $fileInfo[$key]['name'] = $_FILES[$field]['name'][$key];
                 //上传出现错误
                 if (isset($_FILES[$field]['error'][$key]) && $_FILES[$field]['error'][$key] != 0) {
                     $fileInfo[$key]['flag'] = 0 - $_FILES[$field]['error'][$key];
                 } else {
                     //获取扩展名
                     $fileext = IFile::getFileType($_FILES[$field]['tmp_name'][$key]);
                     if (is_array($fileext) || $fileext == null) {
                         $fileext = IFile::getFileSuffix($_FILES[$field]['name'][$key]);
                     }
                     //图片木马检测
                     if (in_array($fileext, $this->checkType) && !IFilter::checkHex($_FILES[$field]['tmp_name'][$key])) {
                         $fileInfo[$key]['flag'] = -9;
                     } else {
                         /*开始上传文件*/
                         //(1)上传类型不符合
                         if (!in_array($fileext, $this->allowType)) {
                             $fileInfo[$key]['flag'] = -7;
                         } else {
                             if ($_FILES[$field]['size'][$key] > $this->maxsize) {
                                 $fileInfo[$key]['flag'] = -8;
                             } else {
                                 //修改图片状态值
                                 $fileInfo[$key]['name'] = ITime::getDateTime('Ymdhis') . mt_rand(100, 999) . '.' . $fileext;
                                 $fileInfo[$key]['dir'] = $this->dir;
                                 $fileInfo[$key]['size'] = $_FILES[$field]['size'][$key];
                                 $fileInfo[$key]['ininame'] = $_FILES[$field]['name'][$key];
                                 $fileInfo[$key]['ext'] = $fileext;
                                 $fileInfo[$key]['fileSrc'] = $fileInfo[$key]['dir'] . $fileInfo[$key]['name'];
                                 $fileInfo[$key]['flag'] = 1;
                                 if ($this->isForge == false) {
                                     if (is_uploaded_file($_FILES[$field]['tmp_name'][$key])) {
                                         IFile::mkdir($this->dir);
                                         move_uploaded_file($_FILES[$field]['tmp_name'][$key], $this->dir . $fileInfo[$key]['name']);
                                     }
                                 } else {
                                     IFile::xcopy($_FILES[$field]['tmp_name'][$key], $this->dir . $fileInfo[$key]['name']);
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $fileInfo[0]['name'] = $_FILES[$field]['name'];
             //上传出现错误
             if (isset($_FILES[$field]['error']) && $_FILES[$field]['error'] != 0) {
                 $fileInfo[0]['flag'] = 0 - $_FILES[$field]['error'];
             } else {
                 //获取扩展名
                 $fileext = IFile::getFileType($_FILES[$field]['tmp_name']);
                 if (is_array($fileext) || $fileext == null) {
                     $fileext = IFile::getFileSuffix($_FILES[$field]['name']);
                 }
                 //图片木马检测
                 if (in_array($fileext, $this->checkType) && !IFilter::checkHex($_FILES[$field]['tmp_name'])) {
                     $fileInfo[0]['flag'] = -9;
                 } else {
                     /*开始上传文件*/
                     //(1)上传类型不符合
                     if (!in_array($fileext, $this->allowType)) {
                         $fileInfo[0]['flag'] = -7;
                     } else {
                         if ($_FILES[$field]['size'] > $this->maxsize) {
                             $fileInfo[0]['flag'] = -8;
                         } else {
                             //修改图片状态值
                             $fileInfo[0]['name'] = ITime::getDateTime('YmdHis') . mt_rand(100, 999) . '.' . $fileext;
                             $fileInfo[0]['dir'] = $this->dir;
                             $fileInfo[0]['size'] = $_FILES[$field]['size'];
                             $fileInfo[0]['ininame'] = $_FILES[$field]['name'];
                             $fileInfo[0]['ext'] = $fileext;
                             $fileInfo[0]['fileSrc'] = $fileInfo[0]['dir'] . $fileInfo[0]['name'];
                             $fileInfo[0]['flag'] = 1;
                             if ($this->isForge == false) {
                                 if (is_uploaded_file($_FILES[$field]['tmp_name'])) {
                                     IFile::mkdir($this->dir);
                                     move_uploaded_file($_FILES[$field]['tmp_name'], $this->dir . $fileInfo[0]['name']);
                                 }
                             } else {
                                 IFile::xcopy($_FILES[$field]['tmp_name'], $this->dir . $fileInfo[0]['name']);
                             }
                         }
                     }
                 }
             }
         }
         $info[$field] = $fileInfo;
     }
     return $info;
 }