0
Ich weiß, meine Frage ist nicht neu, aber ich weiß nicht, warum es nicht funktioniert.Warum funktioniert mein Bildupload nicht?
In meinem Controller, wenn ist falsch und mein Bild wird nicht hochgeladen und die Daten des Bildes nicht in der Datenbank speichern und sonst wird ausgeführt.
<form name="f" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>index.php/aparteman/save" role="form">
<!--<input type="text" name="gh" id="gh"></input>-->
<input type="hidden" name="g" id="g" value=<?php echo $insert_id; ?>></input>
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">
<span class="glyphicon-class glyphicon glyphicon-folder-open"></span> Browse</span>
<input onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none; width:50%;" type="file" name="Name1" id="Name1"></input>
</span>
</form>
MyController
public function save()
{
$config['upload_path']='/upload/';
$config['allowed_types']= 'gif|jpg|png|jpeg';
$config['max_size']= 2000;
$config['max_width']= 1024;
$config['max_height']= 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('Name1'))
{
$data = array('upload_data' => $this->upload->data());
$my_data['photo']=$data['upload_data']['file_name'];
$my_data = array(
'FIDKhane' => $this->input->post('g')
);
$this->load->model('apartemanmodel');
$this->apartemanmodel->insert_images($my_data);
}
else {
echo "...";
}
mein Modell
function insert_images($my_data)
{
$this->db->set('Name1',$my_data['photo']);
$this->db->set('FIDKhane',$my_data['FIDKhane']);
$this->db->insert('imagekhane');
}
Vielen Dank für Ihre Nachschlag.
if ($ this-> upload-> do_upload ('Name1')) dies, wenn kippe, weil seine falsch ausführen .... – Zoee
Sie brauchen nicht Upload zu initialisieren, nachdem loading library – Fiil
Versuchen Sie, Fehler anzuzeigen, indem Sie Folgendes hinzufügen: 'if (! $ this-> upload-> do_upload ('userfile')) { $ error = array ('fehler' => $ this-> upload-> display_errors ()); $ this-> load-> view ('upload_form', $ error); } ' – Fiil