Welcome Guest, Not a member yet? Register   Sign In
Problem uploading multiple Images
#1

[eluser]Dirk Basiscode[/eluser]
Hello there,

i'm just new to CI and have a question regarding multiple file uploads.

I have a form where the user can uplaod 5 pictures.

In my controler i save all the other inputfields in a db and maka one call to a methode to save the images for every image the user submitted.
Code:
...
for ($i=1;$i<=5;$i++)
{
    if($_FILES['image_'.$i]['size'] > 0)
    {
        if($this->uploadFile('image_'.$i, $iNewId))
        {
            $aModelfoto = array();
            $aModelfoto['fk_model']     = $iNewId;
            $aModelfoto['fk_status']    = 3;
            $aModelfoto['bildname']     = $this->aFileData['file_name'];
            // Savind the image in the db
            $this->modelfoto_mdl->add($aModelfoto);
        }
        else
        {
            $this->session->set_flashdata('message', $this->aFileError['error']);
            redirect('admin/modeldetail/add','refresh');
        }
     }
}

in the Methode uploadFile i upload the Image :-) and save the imagedata in a class-variable
Code:
$this->aFileData


Here's the methode:
Code:
private function uploadFile($sFieldname, $iId)
    {
        $aConfig['upload_path']      = $this->sUploadDir.'/'.$iId;
        $aConfig['allowed_types']    = 'gif|jpg|png';
        $aConfig['max_size']         = '5000';
        $aConfig['max_width']        = '3024';
        $aConfig['max_height']       = '2768';

        //ggf. noch den Ordner anlegen
        if (!(is_dir($aConfig['upload_path'])))
        {
            mkdir($aConfig['upload_path']);
        }
        $this->load->library('upload', $aConfig);
        if ( ! $this->upload->do_upload($sFieldname))
        {
            $this->aFileError = array('error' => $this->upload->display_errors());
            return false;
        }    
        else
        {
            $this->aFileData = $this->upload->data();
            return true;
        }
    }

The Problem ist that the first filename is the given filename but for the following images i have just the fileextension after the first imagename. e.g.: image1: name1.jpg image2: name1.jpg.jpg

Can anyone help?
Thanks a lot

Dirk
#2

[eluser]danmontgomery[/eluser]
search is your friend Wink
#3

[eluser]Dirk Basiscode[/eluser]
thanks man. This works. Next time I'll search with more enthusiasm :red:




Theme © iAndrew 2016 - Forum software by © MyBB