|
在上传的model的方法里,在最前面加上:
PHP复制代码
$value = $_FILES['userfile']['name'];
$value = utf8_decode($value);
$value = strtr($value ,
"\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF",
"!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 ,
"\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF",
"!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);
}
}
复制代码
|
评分
-
查看全部评分
|