allow_null) { $this->error = 'presence_of'; } return is_null($this->error); } // ----------------------------------------------------- // Uploaded files are stored in the $_FILES array, so // we use that array instead of the $attributes. // ----------------------------------------------------- $file = Input::file($attribute); if ( ! is_null($this->maximum) and $file['size'] > $this->maximum * 1000) { $this->error = 'file_too_big'; } // ----------------------------------------------------- // The File::is method uses the Fileinfo PHP extension // to determine the MIME type of the file. // ----------------------------------------------------- foreach ($this->types as $type) { if (File::is($type, $file['tmp_name'])) { break; } $this->error = 'file_wrong_type'; } return is_null($this->error); } /** * Set the acceptable file types. * * @return Upload_Of */ public function is() { $this->types = func_get_args(); return $this; } /** * Require that the uploaded file is an image type. * * @return Upload_Of */ public function is_image() { $this->types = array_merge($this->types, array('jpg', 'gif', 'png', 'bmp')); return $this; } /** * Set the maximum file size in kilobytes. * * @param int $maximum * @return Upload_Of */ public function maximum($maximum) { $this->maximum = $maximum; return $this; } /** * Set the validation error message. * * @param string $message * @return Upload_Of */ public function message($message) { return $this->wrong_type($message)->too_big($message); } /** * Set the "wrong type" error message. * * @param string $message * @return Upload_Of */ public function wrong_type($message) { $this->wrong_type = $message; return $this; } /** * Set the "too big" error message. * * @param string $message * @return Upload_Of */ public function too_big($message) { $this->too_big = $message; return $this; } }