public function validate($uploadedFile, &$file, $error, $file_size, $index, $uploadDir)
 {
     if ($error) {
         $file["error"] = $error;
         return false;
     }
     if (!$file["name"]) {
         $file["error"] = "File name was not provided";
         return false;
     }
     if (!preg_match($this->options['accept_file_types'], $file["name"])) {
         $file["error"] = "File type is not acceptable";
         return false;
     }
     if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] * 1024 || $file["size"] > $this->options['max_file_size'] * 1024)) {
         $file["error"] = mysprintf("File size exceeds limit of %s kbytes", array($this->options['max_file_size']));
         return false;
     }
     if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size'] * 1024) {
         $file["error"] = mysprintf("File size must not be less than %s kbytes", array($this->options['min_file_size']));
         return false;
     }
     if (is_int($this->options['max_totalFile_size']) && $this->getUploadFilesSize() + $file["size"] > $this->options['max_totalFile_size'] * 1024) {
         $file["error"] = mysprintf("Total files size exceeds limit of %s kbytes", array($this->options['max_totalFile_size']));
         return false;
     }
     if (is_int($this->options['max_number_of_files']) && ($this->getUploadFilesCount() >= $this->options['max_number_of_files'] && $this->options['max_number_of_files'] > 0)) {
         if ($this->options['max_number_of_files'] > 1) {
             $file["error"] = mysprintf("You can upload no more than %s files", array($this->options['max_number_of_files']));
         } else {
             $file["error"] = "You can upload only one file";
         }
         return false;
     }
     if (isImageType($uploadedFile["type"])) {
         $image_size = runner_getimagesize($uploadedFile["tmp_name"], $uploadedFile);
         $img_width = $image_size[0];
         $img_height = $image_size[1];
         if (is_int($img_width)) {
             if (($this->options['max_width'] && $img_width > $this->options['max_width'] || $this->options['max_height'] && $img_height > $this->options['max_height']) && !$this->options['resizeOnUpload']) {
                 $file["error"] = 'maxResolution';
                 return false;
             }
             if ($this->options['min_width'] && $img_width < $this->options['min_width'] || $this->options['min_height'] && $img_height < $this->options['min_height']) {
                 $file["error"] = 'minResolution';
                 return false;
             }
         }
     }
     return true;
 }
Example #2
0
 public function validate($uploadedFile, &$file, $error, $file_size, $index, $uploadDir)
 {
     if ($error) {
         $file["error"] = $error;
         return false;
     }
     if (!$file["name"]) {
         $file["error"] = "No se ha indicado el nombre de fichero";
         return false;
     }
     if (!preg_match($this->options['accept_file_types'], $file["name"])) {
         $file["error"] = "El tipo de fichero es erróneo";
         return false;
     }
     if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] * 1024 || $file["size"] > $this->options['max_file_size'] * 1024)) {
         $file["error"] = mysprintf("El tamaño del fichero supera el límite de %s KBytes", array($this->options['max_file_size']));
         return false;
     }
     if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size'] * 1024) {
         $file["error"] = mysprintf("El tamaño del fichero no puede ser menor de %s KBytes", array($this->options['min_file_size']));
         return false;
     }
     if (is_int($this->options['max_totalFile_size']) && $this->getUploadFilesSize() + $file["size"] > $this->options['max_totalFile_size'] * 1024) {
         $file["error"] = mysprintf("El tamaño de los ficheros supera el límite de %s KBytes", array($this->options['max_totalFile_size']));
         return false;
     }
     if (is_int($this->options['max_number_of_files']) && ($this->getUploadFilesCount() >= $this->options['max_number_of_files'] && $this->options['max_number_of_files'] > 0)) {
         if ($this->options['max_number_of_files'] > 1) {
             $file["error"] = mysprintf("No puede enviar más de %s ficheros", array($this->options['max_number_of_files']));
         } else {
             $file["error"] = "Solo puede enviar un fichero";
         }
         return false;
     }
     if (isImageType($uploadedFile["type"])) {
         $image_size = runner_getimagesize($uploadedFile["tmp_name"], $uploadedFile);
         $img_width = $image_size[0];
         $img_height = $image_size[1];
         if (is_int($img_width)) {
             if (($this->options['max_width'] && $img_width > $this->options['max_width'] || $this->options['max_height'] && $img_height > $this->options['max_height']) && !$this->options['resizeOnUpload']) {
                 $file["error"] = 'maxResolution';
                 return false;
             }
             if ($this->options['min_width'] && $img_width < $this->options['min_width'] || $this->options['min_height'] && $img_height < $this->options['min_height']) {
                 $file["error"] = 'minResolution';
                 return false;
             }
         }
     }
     return true;
 }