public function validate() { // The upload directory must always be set empty($this->directory) and $this->directory(); // By default, there is no uploaded file $filename = ''; if ($status = parent::validate() and $this->upload['error'] === UPLOAD_ERR_OK) { // Set the filename to the original name $filename = $this->upload['name']; if (Kohana::config('upload.remove_spaces')) { // Remove spaces, due to global upload configuration $filename = preg_replace('/\\s+/', '_', $this->data['value']); } if (file_exists($filepath = $this->directory . $filename)) { if ($this->filename !== TRUE or !is_writable($filepath)) { // Prefix the file so that the filename is unique $filepath = $this->directory . 'uploadfile-' . uniqid(time()) . '-' . $this->upload['name']; } } // Move the uploaded file to the upload directory move_uploaded_file($this->upload['tmp_name'], $filepath); } if (!empty($_POST[$this->data['name']])) { // Reset the POST value to the new filename $this->data['value'] = $_POST[$this->data['name']] = empty($filepath) ? '' : $filepath; } return $status; }
public function validate() { // Validation has already run if (is_bool($this->is_valid)) { return $this->is_valid; } if ($this->input_value() == FALSE) { // No data to validate return $this->is_valid = FALSE; } // Load the submitted value $this->load_value(); if (!array_key_exists($this->value, $this->data['options'])) { // Value does not exist in the options return $this->is_valid = FALSE; } return parent::validate(); }