[英]how can upload image in codeigniter
嘿,我試圖將圖像上傳到我的資產文件夾中。 但是我做不正確。 實際上,我想將圖像保存為“最后插入的ID” 。 我不知道這是什么錯誤。 請幫我
$.ajax({
url: base_url+"register/reg_submit/",
data: $('#career_submit_form').serialize(),//returns all cells' data
dataType: 'json',
type: 'POST',
success: function (res) {
alert(res.result)
},
在我的控制器reg_submit中
$application_insert = $this->career->insert_student_application($personal_details,$parent_details,$other_details);
$config['upload_path'] = './application/assets/images/user_image/';
$config['allowed_types'] = 'jpg';
$config['file_name'] = $application_insert.'.jpg';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile'))
{
echo $this->upload->display_errors();
}
嘗試這個:
public function file_upload(){
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$fileName = $_FILES['userfile']['name'];
$images[] = $fileName;
}
$fileName = implode(',',$images);
$this->my_model->upload_image($fileName);
}
private function set_upload_options()
{
// upload an image options
$config = array();
$config['upload_path'] = './upload/'; //give the path to upload the image in folder
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
有關如何在codeigniter中上傳圖像的更多信息,請嘗試以下方法: http ://w3code.in/2015/09/upload-file-using-codeigniter/
請按照以下步驟
1. check $application_insert variable return anything?
2. change './application/assets/images/user_image/' to "application/assets/images/user_image/"
3. make writable all the folders assests, images and user_image
4. check spelling of the folders are same what you given in the upload path
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.