使用Codeigniter上载徽标在editform上不起作用 [英] Uploading logo using Codeigniter not working on editform

查看:89
本文介绍了使用Codeigniter上载徽标在editform上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于编辑我的公司信息的editform.我也有一个用于上传徽标的字段.当我单击选择文件,然后单击提交(表单)时,它将文件名作为imagename.jpg存储在我的数据库中.

I have an editform for editing my company information. I also have a field for uploading a logo. When I click on choose file, and click Submit (the form) It stores the filename in my database as imagename.jpg for example.

我还想将图像添加到文件夹asset/uploads/中.我使用codeigniter上载类进行了尝试,与在其他上载表单中所做的相同,但是此方法不起作用.我就是不知道为什么.

I also want to add the image to the folder assets/uploads/. I tried it using the codeigniter upload class, same as I did on my other upload form, but this one does not work. I just don't know why.

这是我的编辑表单:

<?= form_open_multipart('members/update/'.$id);?>
//other fields for editing company
    <tr>
    <td><?= form_label('Logo:'); ?></td>
    <td><input type="file" name="logo" size="20" /></td>
    </tr>


    <tr>
    <td><?= form_submit('submit', 'Opslaan');?> <?= form_reset('reset', 'Reset');?></td>
    </tr>

</table>
<?= form_close()?>

我的控制器:

function update() //de update functie voor bovenstaande functie.
{
    $id = $this->uri->segment(3);
    $data = array(
       'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'),
       'Postcode' => $this->input->post('Postcode'),
       'Plaats' => $this->input->post('Plaats'),
       'Telefoonnummer' => $this->input->post('Telefoonnummer'),
       'Email' => $this->input->post('Email'),
       'Website' => $this->input->post('Website'),
       'Profiel' => $this->input->post('Profiel'),
       'Adres' => $this->input->post('Adres'),
    );
    if($this->input->post('logo')) { $data['logo'] = $this->input->post('logo'); }
    $config['upload_path'] = './assets/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width']  = '';
    $config['max_height']  = '';
    $config['overwrite'] = TRUE;
    $config['remove_spaces'] = TRUE;

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

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
    }
    $this->members_model->updatebedrijf($id, $data);

    $b = $this->session->userdata('idbedrijven');
    redirect("members/$b");
}   
function updatebedrijf($id, $data)
{
    foreach($this->input->post('categorieen') as $cat){
        $this->db->where('idbedrijven', $id);
        $this->db->update('bedrijven', $data); 

        $to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
        $this->insert_bedrijfcat1($to_bedrijfcategorieen2); 
    };

}

我的模特:

function updatebedrijf($id, $data)
{
    foreach($this->input->post('categorieen') as $cat){
        $this->db->where('idbedrijven', $id);
        $this->db->update('bedrijven', $data); 

        $to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
        $this->insert_bedrijfcat1($to_bedrijfcategorieen2); 
    };

}

它只是不上传.该路径与我的其他上载功能相同.那个很好用.

It just does not upload. The path is the same as my other uploadfunction. that one works fine.

推荐答案

您尚未在do_upload函数

 if ( ! $this->upload->do_upload("logo"))
{
    $error = array('error' => $this->upload->display_errors());
}else{
 $image_data = $this->upload->data();

}

这是一件错误的事情,您需要对logo字段进行if检查,而您正试图发布在帖子中,为什么?应该是

And there is one thing wrong you have a if check for logo field and you are trying to get in post why ?? it should be

if($_FILES['logo']['name'] != '') { $data['logo'] = $_FILES['logo']['name']; }

这篇关于使用Codeigniter上载徽标在editform上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆