中级会员
$value = $_FILES['userfile']['name'];$value = utf8_decode($value);$value = strtr($value ,"xA1xAAxBAxBFxC0xC1xC2xC3xC5xC7xC8xC9xCAxCBxCCxCDxCExCFxD0xD1xD2xD3xD4xD5xD8xD9xDAxDBxDDxE0xE1xE2xE3xE5xE7xE8xE9xEAxEBxECxEDxEExEFxF0xF1xF2xF3xF4xF5xF8xF9xFAxFBxFDxFF","!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");$value = preg_replace('/( +)/i', '_', $value);$value = strtolower($value);$_FILES['userfile']['name'] = $value; //你的代码可能会像这样:function new_sample_file_add($id) { $value = $_FILES['userfile']['name']; $value = utf8_decode($value); $value = strtr($value , "xA1xAAxBAxBFxC0xC1xC2xC3xC5xC7xC8xC9xCAxCBxCCxCDxCExCFxD0xD1xD2xD3xD4xD5xD8xD9xDAxDBxDDxE0xE1xE2xE3xE5xE7xE8xE9xEAxEBxECxEDxEExEFxF0xF1xF2xF3xF4xF5xF8xF9xFAxFBxFDxFF", "!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy"); $value = preg_replace('/( +)/i', '_', $value); $value = date('Y_m_d_H_i_s__').$this->session->userdata('username').'_'.$value; $value = strtolower($value); $_FILES['userfile']['name'] = $value; $this->load->library('upload'); $this->load->helper('date'); $config = array(); $upload_path = 'upload/myconsumeo/'.date('Y').'/'; $config['upload_path'] = './'.$upload_path; $config['allowed_types'] = 'gif|jpg|png|pdf|doc|xsl|rar|zip'; $config['max_size'] = '10240'; // $config['max_width'] = '2048'; // $config['max_height'] = '1536'; // $config['encrypt_name'] = true; $this->upload->initialize($config); if ( ! $this->upload->do_upload()) { $this->session->set_flashdata('my_info', $this->upload->display_errors()); redirect('my/new_sample_file_add/'.$id); } else { ////////////////////////prepare insert to database/////////////////// $data = $this->upload->data(); $file_url = $data['raw_name'].$data['file_ext']; /////////////////////////insert into database////////// $this->session->set_flashdata('my_info', 'File upload successed'); $temp = array( 'new_sample_id' => $id, 'description' => $_POST['description'], 'file_url '=> $upload_path . $data['orig_name'], // 'file_name'=>$data['file_name'], 'file_type'=>$data['file_type'], 'file_size'=>$data['file_size'], 'file_name'=>$data['orig_name'], 'date_add' =>date("Y-m-d H:i:s",time()), ); $this->db->insert('my_new_sample_file',$temp); redirect('my/my_samples/'.$id); } }
查看详细资料
TOP
Lee
高级会员
孤夜娇狼
查看个人网站
男人
版主