public function action_upload() { $field = 'Filedata'; if (($value = Arr::get($_FILES, $field, FALSE)) === FALSE) { $this->request->response = 'error'; return; } if (!Upload::not_empty($value) or !Upload::valid($value)) { $this->request->response = 'error'; return; } if ($tmp_name = Torn_Uploader::upload_to_cache($value, $field)) { $this->request->response = 'done;' . $tmp_name; } else { $this->request->response = 'error'; } }
public function invoke(Validate $array, $field) { $value = $array[$field]; if (!is_array($value)) { return TRUE; } $cache = Cache::instance(); $surfix = Kohana::config('torn')->surfix->temp; $cached = $this->model->get($field . $surfix); $current = $this->model->get($field, FALSE); $used_cached = FALSE; $empty_check = FALSE; if (!Upload::not_empty($value) and empty($cached) and !empty($current)) { $this->model->set($field, $current); $array[$field] = $current; return TRUE; } if (!Upload::not_empty($value) and preg_match('/^[a-z0-9]{32}-[a-z0-9]{32}$/iD', $cached)) { $value = Arr::get($cache->get($cached), 'upload', $value); $used_cached = TRUE; } $modified_rules = $this->rules; foreach ($this->rules as $rule => $params) { if (!utf8::strcasecmp($rule, 'Upload::not_empty')) { unset($modified_rules[$rule]); $modified_rules['Torn_Uploader::not_empty'] = NULL; break; } } $validate = Validate::factory(array($field => $value))->filters($field, $this->filters)->rules($field, $modified_rules)->callbacks($field, $this->callbacks); if (!$validate->check()) { foreach ($validate->errors() as $v) { list($error, $params) = $v; $array->error($field, $error, $params); } return FALSE; } $validate = $array->as_array(); $value = $validate[$field]; if ($tmp_name = Torn_Uploader::upload_to_cache($value, $field) and !$used_cached) { $array[$field] = $tmp_name; } else { $array[$field] = Arr::get($_POST, $field . $surfix, $value); } $this->model->set($field, $array[$field]); return TRUE; }