function check()
 {
     if (isset($_FILES[$this->ref])) {
         $this->fileInfo = $_FILES[$this->ref];
     } else {
         $this->fileInfo = array('name' => '', 'type' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE);
     }
     if ($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->required) {
             return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
         }
     } else {
         if ($this->fileInfo['error'] == UPLOAD_ERR_NO_TMP_DIR || $this->fileInfo['error'] == UPLOAD_ERR_CANT_WRITE) {
             return $this->container->errors[$this->ref] = jForms::ERRDATA_FILE_UPLOAD_ERROR;
         }
         if ($this->fileInfo['error'] == UPLOAD_ERR_INI_SIZE || $this->fileInfo['error'] == UPLOAD_ERR_FORM_SIZE || $this->maxsize && $this->fileInfo['size'] > $this->maxsize) {
             return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_SIZE;
         }
         if ($this->fileInfo['error'] == UPLOAD_ERR_PARTIAL || !is_uploaded_file($this->fileInfo['tmp_name'])) {
             return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
         }
         if (count($this->mimetype)) {
             $this->fileInfo['type'] = \Jelix\FileUtilities\File::getMimeType($this->fileInfo['tmp_name']);
             if ($this->fileInfo['type'] == 'application/octet-stream') {
                 // let's try with the name
                 $this->fileInfo['type'] = \Jelix\FileUtilities\File::getMimeTypeFromFilename($this->fileInfo['name']);
             }
             if (!in_array($this->fileInfo['type'], $this->mimetype)) {
                 return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_TYPE;
             }
         }
     }
     return null;
 }
Beispiel #2
0
 /**
  * get the MIME Type of a file
  *
  * @param string $file The full path of the file
  * @return string the MIME type of the file
  * @since 1.1.6
  * @deprecated  use \Jelix\FileUtilities\File::getMimeType() instead
  */
 public static function getMimeType($file)
 {
     trigger_error("jFile::getMimeType is deprecated. Use \\Jelix\\FileUtilities\\File::getMimeType() instead.", E_USER_DEPRECATED);
     return File::getMimeType($file);
 }