Wie zum hochladen von image-Pfad und-name, Datenbank - Codeigniter

Ich weiß, diese Frage wurde schon mehrfach gefragt, aber auch alle anderen Frage, die ich fand, sind Verschieden von dem, was ich will.

Will ich hochladen, den Dateinamen und den Dateipfad zu einer Tabelle namens "factoryimages'.

Was ist der beste Weg, dies zu tun?

Mein controller Funktion:

function do_upload()
{
    $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());

        $this->load->view('members/header');
        $this->load->view('members/upload_form', $error);
        $this->load->view('members/footer');
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $this->load->view('members/header');
        $this->load->view('members/upload_success', $data);
        $this->load->view('members/footer');
    }
}

Versuchte ich dieses in mein Modell, aber es hat nicht funktioniert:

function insert_images()
{
    $insert_data = array(
    'filename' => $image_data['file_name'],
    'fullpath' => $image_data['full_path']
    );

    $this->db->insert('bedrijfimages', $insert_data);
}

Meiner Sicht:

<?php echo $error;?>
<br/>
<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" multiple="true" />

<br /><br />

<input type="submit" value="upload" />

</form>

Edit:

Bekomme ich einen server-Fehler, aber ich kann nicht sehen, was es ist.

Mein controller Funktion:

function do_upload()
{
    $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());
        $this->upload_model->insert_images($this->upload->data());
        $this->load->view('members/header');
        $this->load->view('members/upload_form', $error);
        $this->load->view('members/footer');
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $this->load->view('members/header');
        $this->load->view('members/upload_success', $data);
        $this->load->view('members/footer');
    }
}

Mein Modell Funktion:

function insert_images($data = array())
{
    $data = array(
    'filename' => $image_data['file_name'],
    'fullpath' => $image_data['full_path']
    );

    $this->db->insert('bedrijfimages', $data);
}

Was das problem sein könnte?

InformationsquelleAutor Kees Sonnema | 2013-04-24

Schreibe einen Kommentar