gpt4 book ai didi

php - 使用 codeigniter 上传时为 "did not select a file to upload"

转载 作者:可可西里 更新时间:2023-11-01 12:41:12 33 4
gpt4 key购买 nike

我正在尝试上传图片,但它总是提示“您没有选择要上传的文件。”

我的 Controller

function add()
{

$thedate=date('Y/n/j h:i:s');
$replace = array(":"," ","/");
$newname=str_ireplace($replace, "-", $thedate);

$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name']=$newname;
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';

$this->load->library('upload', $config);
//$this->upload->initialize($config);
$this->load->library('form_validation');

$this->form_validation->set_rules('title','title','trim|required');
$this->form_validation->set_rules('description','Description','trim|required');
$image1=$this->input->post('image');


if ($this->form_validation->run()==FALSE){

$this->addview();

return false;

}


if (!$this->upload->do_upload($image1)) {

$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_error', $error);


}

else {
$mage=$this->upload->do_upload($image1);

$data =array(
'title'=>$this->input->post('title'),
'descrip'=>$this->input->post('description'),

'image' => $mage['file_name']

);


$this->load->model('member_functions');

$q=$this->member_functions->insert($data);
}}

所有文件要求和文件权限都已设置,但我仍然收到该错误。有人可以告诉我我做错了什么吗

最佳答案

$this->upload->do_upload() 函数的参数应该是表单字段的名称。 (如果您不带参数调用它,将使用 userfile)。在您的情况下,它似乎应该是“图像”。而不是:

$image1=$this->input->post('image');

应该是:

$image1='image';

关于php - 使用 codeigniter 上传时为 "did not select a file to upload",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7457152/

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