CodeIgniter Forums
uoploading more than one file. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: uoploading more than one file. (/showthread.php?tid=10732)



uoploading more than one file. - El Forum - 08-10-2008

[eluser]PHP Programmer[/eluser]
I have uploaded one file but I have other options to upload other files also on the same page. I have to upload them (two files more)separately without making an array. If I give the name other than userfile then no more files get uoplaoded. How can I do get success?


uoploading more than one file. - El Forum - 08-10-2008

[eluser]Colin Williams[/eluser]
Run the upload process for each field:

Code:
$this->upload->do_upload('userfile');
$this->upload->do_upload('otherfile');
$this->upload->do_upload('anotherfile');

Sounds like you added fields on the front end and did nothing on the back-end to accommodate. It isn't magic ya know! Smile


uoploading more than one file. - El Forum - 08-10-2008

[eluser]Sumon[/eluser]
I have an example which might helpful for you. It re size image as well.
Code:
if(basename($_FILES['filePhoto1']['name'])!="")
    $FileName[]=Photo::FileUploadWithResize("filePhoto1");
if(basename($_FILES['filePhoto2']['name'])!="")
    $FileName[]=Photo::FileUploadWithResize("filePhoto2");
if(basename($_FILES['filePhoto3']['name'])!="")
    $FileName[]=Photo::FileUploadWithResize("filePhoto3");

function FileUploadWithResize($FileFieldName)
{
    $config['upload_path'] = './gallery/image_gallery/tmp_photos/';    //Change it by your image folder name
    $config['allowed_types'] = 'gif|jpg|jpeg|png';
    $config['max_size']    = '10000';
    $config['max_width']  = '4000';
    $config['overwrite']  = FALSE;
    $config['max_height']  = '4000';
    $this->load->library('upload', $config);
    // Upload Main Picture into tmp_photos
    if($this->upload->do_upload($FileFieldName))
    {
        $FileData=$this->upload->data();    //echo "Upload hoise.";
        $MainFileName=$FileData['file_name'];
        $ThumbFileNameByCI=substr($MainFileName,0,strpos($MainFileName,".")) . "_thumb".substr($MainFileName,strpos($MainFileName,"."));
    }
    else
    {
        $error = array('error' => $this->upload->display_errors());    //echo $error['error'];
        $this->session->set_userdata("UploadErrors" , $this->session->userdata("UploadErrors")."<br>".$error['error']);
        return FALSE;
    }
    
    // Resize $MainFileName to BigPicture (600X450) into original_photo
    unset($config);
    $config['image_library'] = 'GD2';
    $config['source_image'] = './gallery/image_gallery/tmp_photos/'.$MainFileName;    //Change it by your image folder name
    //$config ['quality'] = '80%';
    $config['master_dim'] = 'auto';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 600;
    $config['height'] = 450;
    $config['new_image'] = './gallery/image_gallery/photo_original/'.$MainFileName;
    $this->load->library('image_lib', $config);
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    unset($config);
    $this->image_lib->clear();
    return $ThumbFileNameByCI;
}



uoploading more than one file. - El Forum - 08-11-2008

[eluser]PHP Programmer[/eluser]
thanks for your replies...it worked Smile