0

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

我还想将图像添加到文件夹 assets/uploads/。我尝试使用 codeigniter 上传类,就像我在其他上传表单上所做的一样,但是这个不起作用。我只是不知道为什么。

这是我的编辑表格:

<?= 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); 
    };

}

它只是不上传。该路径与我的其他上传功能相同。那个工作正常。

4

3 回答 3

1

您尚未在do_upload函数中设置字段名称

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

}

还有一件事是错误的,你有一个 if 检查logo字段并且你试图进入帖子为什么?它应该是

if($_FILES['logo']['name'] != '') { $data['logo'] = $_FILES['logo']['name']; }
于 2013-06-13T08:08:16.067 回答
0
if ( ! $this->upload->do_upload(?))

您应该将文件名设置为上传函数的参数,因为它不是默认的“用户文件”?

于 2013-06-13T07:44:50.073 回答
0

没有任何解决方案被唤醒。这是我想出的方法。

if ($_FILES['userfile']['name'] != null) {
            // upload configuration
            $upload_config = array(
                'upload_path' => './assets/uploads/',
                'allowed_types' => 'jpeg|jpg|png',
                'max_size' => 1048576,
                'max_width' => 10240,
                'max_height' => 7680,
                'encrypt_name' => TRUE
            );
            // load upload library config
            $this->load->library('upload', $upload_config);
            if (!$this->upload->do_upload()) {
                // assign upload errors
                $data['upload_errors'] = $this->upload->display_errors();
                // load page title
                $page['title'] = "Edit Parent";
                // fetch parent information
                $this->db->select('Database Query');
                // info data in row
                $data['info'] = $this->db->get()->row();
                // load view with page title
                $this->load->view('temp/header', $page);
                $this->load->view('editParents', $data);
                $this->load->view('temp/footer');
            } else {
                $upload_photo = $this->upload->data();
                // profile image
                $parent_photo = $upload_photo['file_name'];
            }
        } else {
            // profile image
            $parent_photo = $this->input->post('profile_image');
        }
于 2016-12-17T06:55:55.373 回答