ci框架圖片上傳
public function upload_img(){
$config['upload_path'] = './uploads/tenants/hospital_picture';//設置上傳路徑
$config['allowed_types'] = 'gif|jpg|png|jpeg'; //設置圖片類型
$config['file_name'] = date('YmdHis').rand(1000,9999);//配置圖片名稱
$this->load->library('upload', $config);//加載ci自帶的圖片上傳插件
// print_r($this->upload->data());//打印上傳信息
if (!$this->upload->do_upload('file_name'))//上傳文件
{
$this->return['status'] = 'fail';
$this->return['msg'] = $this->upload->display_errors();//顯示錯誤信息
$this->result();
}else{
$data = $this->upload->data();//獲取上傳信息
$path = base_url('uploads/tenants/hospital_picture/').$data['file_name'];//拼接出文件路徑
$this->return['data'] = $path;//將地址返回到前臺
$this->result();
}
}
$config['upload_path'] = './uploads/tenants/hospital_picture';//設置上傳路徑
$config['allowed_types'] = 'gif|jpg|png|jpeg'; //設置圖片類型
$config['file_name'] = date('YmdHis').rand(1000,9999);//配置圖片名稱
$this->load->library('upload', $config);//加載ci自帶的圖片上傳插件
// print_r($this->upload->data());//打印上傳信息
if (!$this->upload->do_upload('file_name'))//上傳文件
{
$this->return['status'] = 'fail';
$this->return['msg'] = $this->upload->display_errors();//顯示錯誤信息
$this->result();
}else{
$data = $this->upload->data();//獲取上傳信息
$path = base_url('uploads/tenants/hospital_picture/').$data['file_name'];//拼接出文件路徑
$this->return['data'] = $path;//將地址返回到前臺
$this->result();
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.