如何在Codeigniter的公司表格中添加徽标路径? [英] How to add a logo path to my company table in Codeigniter?

查看:174
本文介绍了如何在Codeigniter的公司表格中添加徽标路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于将公司添加到我的数据库的表单。我添加了一个名为Logo的字段。我想使用此字段,以便用户可以上传他们公司的徽标。我在表单中使用Codeigniter上传类。



我的公司表如下所示:

 公司
---------
id
公司名称
地址
邮政编码
国家
电子邮件
网站
徽标

我的表单看起来像这样:

 < tr> 
< td><?= form_label('Bedrijfsnaam:');?>< / td>
< td><?= form_input('Bedrijfsnaam');?>< small> (Spaties niet toegestaan​​)< / small>< / td>
< / tr>

< tr>
< td><?= form_label('Adres:');?>< / td>
< td><?= form_input('Adres');?>< / td>
< / tr>

< tr>
< td><?= form_label('Postcode:');?>< / td>
< td><?= form_input('Postcode');?>< / td>
< / tr>

< tr>
< td><?= form_label('Plaats:');?>< / td>
< td><?= form_input('Plaats');?>< / td>
< / tr>

< tr>
< td><?= form_label('Telefoonnummer:');?>< / td>
< td><?= form_input('Telefoonnummer');?>< / td>
< / tr>

< tr>
< td><?= form_label('Website:');?>< / td>
< td><?= form_input('Website');?>< / td>
< / tr>

< tr>
< td><?= form_label('Email:');?>< / td>
< td><?= form_input('Email');?>< / td>
< / tr>

< tr>
< td><?= form_label('Profiel:');?>< / td>
< td><?= form_textarea('Profiel');?>< / td>
< / tr>

< tr>
< td><?= form_label('Categorieen:'); ?>< / TD>
< td><?= form_dropdown('categorieen',$ opties); ?>< / TD>
< / tr>

< tr>
< td><?= form_label('Logo:'); ?>< / TD>
< td>< input type =filename =logosize =20/>< / td>
< / tr>

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

我的模型如下所示:

<$ p $ b $'''$'$ $ $ $''$,$ $ $'$'$,$ $ $''','$'$'$' $ this-> input-> post('Postcode'),
'Plaats'=> $ this-> input-> post('Plaats'),
'Telefoonnummer'= > $ this-> input-> post('Telefoonnummer'),
'Email'=> $ this->输入 - >邮件('电子邮件'),
'网站'=> $ this-> input-> post('Website'),
'Profiel'=> $ this-> input-> post('Profiel'),
'Adres'=> $ this-> input-> post('Adres'),
'logo'=> $ this-> input-> post('logo')
);
$ this-> db-> insert('bedrijven',$ data1);

我知道这是行不通的,但我无法弄清楚如何做到这一点。 p>

我有另一个上传表单,但只用于上传图片,而不用于标识。



最好的方法是这使用上传类?






编辑:



我我添加一家新公司时获得一个空白字段。



我的管理员:

  function addbedrijven()
{
$ 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->加载 - >库('upload',$ config);

if($ this-> upload-> do_upload('logo')){

$ logo_image_data = $ this-> upload-> data() ;

}
$ this-> members_model-> addbedrijf();
重定向('members / index');

$ / code>

我的模特:

< pre $ function addbedrijf()
{
$ logo_image_data = $ this-> upload-> data();

$ data1 = array(
'Bedrijfsnaam'=> $ this-> input-> post('Bedrijfsnaam'),
'Postcode'=> $ ('邮政编码'),
'Plaats'=> $ this->输入 - >邮政('Plaats'),
'Telefoonnummer'=> ; $ this-> input-> post('Telefoonnummer'),
'Email'=> $ this-> input-> post('Email'),
' ='$ this-> input-> post('Website'),
'Profiel'=> $ this-> input-> post('Profiel'),
' Adres'=> $ this-> input-> post('Adres'),
'logo'=> $ logo_image_data ['full_path']
);
$ this-> db-> insert('bedrijven',$ data1);


解决方案

您可以使用 codeigniter upload class在同一个表单中

  $ config_logo_image = array(
'allowed_types'=>'jpg | jpeg | gif | png',
'upload_path'=> UPLOAD_PATH,
'max_size'= > 2000,
);
$ this->加载 - >库('upload',$ config_logo_image);
if($ this-> upload-> do_upload('logo_image')){

$ logo_image_data = $ this-> upload-> data();

}

并通过您的 $ data array

  $ data1 = 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'),
'logo'=> $ logo_image_data ['full_path'] //它是图片的完整路径
);
$ this-> db-> insert('bedrijven',$ data1);

'logo'=> $ logo_image_data ['file_name'] //只有文件名



希望它有道理


I have an form for adding companies to my database. I've added a field called Logo. I want to use this field so the user can upload an Logo for their company. I am using the Codeigniter upload class in my form.

My company table looks like this:

Companies
---------
id
companyname
address
postalcode
country
email
website
logo

My form looks liek this:

<tr>
<td><?= form_label('Bedrijfsnaam:');?></td>
<td><?= form_input('Bedrijfsnaam');?><small> (Spaties niet toegestaan)</small></td>
</tr>

<tr>
<td><?= form_label('Adres:');?></td>
<td><?= form_input('Adres');?></td>
</tr>

<tr>
<td><?= form_label('Postcode:');?></td>
<td><?= form_input('Postcode');?></td>
</tr>

<tr>
<td><?= form_label('Plaats:');?></td>
<td><?= form_input('Plaats');?></td>
</tr>

<tr>
<td><?= form_label('Telefoonnummer:');?></td>
<td><?= form_input('Telefoonnummer');?></td>
</tr>

<tr>
<td><?= form_label('Website:');?></td>
<td><?= form_input('Website');?></td>
</tr>

<tr>
<td><?= form_label('Email:');?></td>
<td><?= form_input('Email');?></td>
</tr>

<tr>
<td><?= form_label('Profiel:');?></td>
<td><?= form_textarea('Profiel');?></td>
</tr>

<tr>
<td><?= form_label('Categorieen:'); ?></td>
<td><?= form_dropdown('categorieen', $opties); ?></td>
</tr>

<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>

My model looks like this:

    $data1 = 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'), 
        'logo' => $this->input->post('logo') 
    ); 
    $this->db->insert('bedrijven',$data1); 

I know this won't work but I can't figure out how to do this.

I have another uploadform but that's only for uploading images, not for the logo.

What's the best way to do this using the upload class?


EDIT:

I get an empty field when I add a new company.

My controller:

    function addbedrijven()
    {
        $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('logo')){

        $logo_image_data = $this->upload->data();

        }
        $this->members_model->addbedrijf();
        redirect('members/index');
    }

My Model:

    function addbedrijf() 
    { 
        $logo_image_data = $this->upload->data();

        $data1 = 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'), 
            'logo' => $logo_image_data['full_path'] 
        ); 
        $this->db->insert('bedrijven',$data1); 
    }

解决方案

you can use the codeigniter upload class within the same form

      $config_logo_image = array(
        'allowed_types' => 'jpg|jpeg|gif|png',
        'upload_path' => UPLOAD_PATH,
        'max_size' => 2000,
        );
    $this->load->library('upload', $config_logo_image );                    
    if($this->upload->do_upload('logo_image')){

    $logo_image_data = $this->upload->data();

    }

And through this data in the your $data array

    $data1 = 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'), 
    'logo' => $logo_image_data ['full_path']  // it is full path of image 
); 
$this->db->insert('bedrijven',$data1); 

'logo' =>$logo_image_data ['file_name'] //only file name

Hope it makes sense

这篇关于如何在Codeigniter的公司表格中添加徽标路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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