【发布时间】:2015-06-07 19:00:34
【问题描述】:
我已完成文件上传,但如果文件名为“213134.jpg”但我的代码存储数据库仅名称“213134”而没有文件类型。你能帮我么。我已使用 CI 完成此任务
function postMessage(){
$config['upload_path'] = './uploads/inbox/';
$config['allowed_types'] = 'jpg';
$config['max_size'] = '2048';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$random=rand(00000, 99999);
$id=$this->session->userdata('id');
$pic=$id*$random;
$config['file_name'] =$pic;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$blog_msg ='Sorry, Picture uploaded.';
}
$u_id=$this->session->userdata('id');
$u_name=$this->session->userdata('u_fname');
$to=$this->uri->segment(3);
$date= $date=date('d-M-Y');
$message=$_POST["message"];
$data=array(
'm_from'=>$u_id,
'from_name'=>$u_name,
'm_date'=>$date,
'm_body'=>$message,
'm_to'=>$to,
'm_attach'=>$pic
);
}
【问题讨论】:
-
你的数据库代码在哪里?
-
请修复代码标记。
-
$inputed=$this->db->insert($this->message,$data); $insert_id = $this->db->insert_id(); $this->db->trans_complete();返回 $insert_id;
-
$pic=$id*$random;应该是这样的$pic=$id*$random.'.jpg'; -
类型肯定是.jpg而不是.jpeg?如果 .jpg 使用 'allowed_types' => 'jpg|jpeg'