gpt4 book ai didi

jquery - 表单在 codeigniter 的上传文件夹中两次上传相同的文件

转载 作者:行者123 更新时间:2023-11-28 15:07:14 25 4
gpt4 key购买 nike

我正在尝试使用 ajax 上传图片,图片上传并正确存储到数据库,它在上传文件夹中上传了两次。

if(!empty($_FILES)){
$uploadconfig = array(
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '204800',
'file_name' => $_FILES['file']['name'],
'encrypt_name' => TRUE
);

//print_r($uploadconfig); exit;

$this->load->library('upload', $uploadconfig);

if ( ! $this->upload->do_upload("file")) {
echo "failed to upload file(s)";
}
$this->upload->initialize($uploadconfig);
$this->upload->do_upload("file");
$upload_data = $this->upload->data();
$user_profile = $upload_data['file_name'];

$data = array();
$data['first_name'] = $this->input->post('xx_first_name');
$data['last_name'] = $this->input->post('xx_last_name');
$data['email'] = $this->input->post('db_email');
$data['user_dob'] = $this->input->post('db_dob');
$data['user_zip'] = $this->input->post('user_zip');
$data['user_img'] = $user_profile;
}

最佳答案

你已经使用了 $this->upload->do_upload("file") 两次。

试试这个:

if (!empty($_FILES)) {
$uploadconfig = array(
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '204800',
'file_name' => $_FILES['file']['name'],
'encrypt_name' => TRUE
);

$this->load->library('upload', $uploadconfig); // Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class
// $this->upload->initialize($uploadconfig); // I thinks its not required because you have already done it in previous line.
if (!$this->upload->do_upload("file")) {
echo "Failed to upload file(s)";
$upload_data = array();
$user_profile = $_FILES['file']['name'];
// you will error reason here on `$this->upload->display_errors()`
} else {
$upload_data = $this->upload->data();
$user_profile = $upload_data['file_name'];
}

$data = array();
$data['first_name'] = $this->input->post('xx_first_name');
$data['last_name'] = $this->input->post('xx_last_name');
$data['email'] = $this->input->post('db_email');
$data['user_dob'] = $this->input->post('db_dob');
$data['user_zip'] = $this->input->post('user_zip');
$data['user_img'] = $user_profile;
}

关于jquery - 表单在 codeigniter 的上传文件夹中两次上传相同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49145114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com