public function test_verify_uploaded_files_uploadError() { $CI =& get_instance(); $a = array(array("name" => "foobar.txt", "type" => "text/plain", "tmp_name" => NULL, "error" => UPLOAD_ERR_NO_FILE, "size" => 1, "formfield" => "file[1]")); try { \service\files::verify_uploaded_files($a); $this->t->fail("verify should error"); } catch (\exceptions\UserInputException $e) { $data = $e->get_data(); $this->t->is($e->get_error_id(), "file/upload-verify", "verify should error"); $this->t->is_deeply(array('file[1]' => array('filename' => 'foobar.txt', 'formfield' => 'file[1]', 'message' => 'No file was uploaded')), $data, "expected data in exception"); } }
public function upload() { $this->muser->require_access("basic"); $files = getNormalizedFILES(); if (empty($files)) { throw new \exceptions\PublicApiException("file/no-file", "No file was uploaded or unknown error occurred."); } \service\files::verify_uploaded_files($files); $limits = $this->muser->get_upload_id_limits(); $urls = array(); foreach ($files as $file) { $id = $this->mfile->new_id($limits[0], $limits[1]); \service\files::add_uploaded_file($id, $file["tmp_name"], $file["name"]); $ids[] = $id; $urls[] = site_url($id) . '/'; } return array("ids" => $ids, "urls" => $urls); }