function form() { echo '<form action="/ci/upload/do_upload" enctype="multipart/form-data" method="post"> <input name="file" type="file"> <button type="submit">Submit</button> </form>'; } function do_upload() { $config['upload_path'] = $this->_file_path; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); print_r($_FILES); if ( ! $this->upload->do_upload('file')) { print_r($this->upload->data()); $error = $this->upload->display_errors(); $this->common->ajax_callback('fail', '' . $error); } // @todo Image resize $data = $this->upload->data(); $this->common->ajax_callback('success', ''); }
Array ( [file] => Array ( [name] => p3.jpg [type] => image/jpeg [tmp_name] => E:\xampp\tmp\php41E.tmp [error] => 0 [size] => 135027 ) ) Array ( [file_name] => p3.jpg [file_type] => [file_path] => E:/web/ci/file/update/ [full_path] => E:/web/ci/file/update/p3.jpg [raw_name] => p3 [orig_name] => [client_name] => p3.jpg [file_ext] => .jpg [file_size] => 135027 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ) {"status":"fail","message":"\u4e0a\u50b3\u5931\u6557<br \/><p>The filetype you are attempting to upload is not allowed.<\/p>"}