Example #1
0
 /**
  * 检测单个文件的后缀是否符合要求
  * @param string $field 要检查的表单字段名
  * @param string $filename 上传的本地文件名
  * @param string $file 上传到临时目录下的文件路径
  */
 public function checkExt($field, $filename, $file)
 {
     $ext = Fso::getExt($filename);
     if (isset($this->allowExts[$field])) {
         if (is_array($this->allowExts[$field]) && !in_array($ext, $this->allowExts[$field])) {
             $this->error = true;
             $this->errorField = $field;
             $this->errorFile = $filename;
             $this->setNotAllowExtsErrorMsg($filename, $this->{$this}->allowExts[$field]);
             return false;
         } else {
             if ($ext != $this->allowExts[$field]) {
                 $this->error = true;
                 $this->errorField = $field;
                 $this->errorFile = $filename;
                 $this->setNotAllowExtsErrorMsg($filename, $this->{$this}->allowExts[$field]);
                 return false;
             }
         }
     } else {
         if (!in_array($ext, $this->allowExts)) {
             $this->error = true;
             $this->errorField = $field;
             $this->errorFile = $filename;
             $this->setNotAllowExtsErrorMsg($filename, $this->allowExts);
             return false;
         } else {
             $ret = Fso::isExtMatchMime($ext, $file);
             if (!$ret) {
                 $msg = Core::getLang('upload_file_extension_not_match_mime_type');
                 $replacement = array('{file}' => $filename, '{mime-type}' => Fso::getMimeType($file));
                 $this->error(strtr($msg, $replacement));
                 $this->error = true;
                 $this->errorField = $field;
                 $this->errorFile = $filename;
             }
             return $ret;
         }
     }
 }
Example #2
0
File: FsoTest.php Project: irs/fso
 /**
  * @expectedException InvalidArgumentException
  */
 public function testDeleteOnNotExistentFilesShouldThrowInvalidArgumentException()
 {
     Fso::delete(uniqid());
 }