Part of the EllisLab Network
   
2 of 2
2
Single, Multiple and Multiple array upload library
Posted: 21 May 2010 05:01 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  8
Joined  11-05-2009

Hello everyone, I am using code similar to this. if anyone can help me.

Thx.

http://codeigniter.com/forums/viewthread/155820/

Profile
 
 
Posted: 25 June 2010 06:13 AM   [ Ignore ]   [ # 17 ]  
Summer Student
Total Posts:  14
Joined  04-08-2010

Thanks for this, I almost have it working, but I am having problems adding the uploaded files to my database, can anybody help?
Here is my controller function…

function addStation(){
        
// set common properties
        
$data['title''Add new station';
        
$data['action'site_url('admin/station/addStation');
        
$data['link_back'anchor('admin/station/index/','Back to list of stations',array('class'=>'back'));
        
        
// set validation properties
        
$this->_set_fields();
        
$this->_set_rules();
            
        
$config['allowed_types''pdf|xls|doc|docx';
    
$config['max_size''1000';
    
$config['max_width']  '1024';
    
$config['max_height']  '768';
    
$path_to_uploads='./uploads/files/stations';
    
$config['upload_path'$path_to_uploads;
    
    
// File specific (overrule global and optional)
$config['logo_file']['upload_path']   './uploads/images/stations';
$config['logo_file']['allowed_types''gif|jpg|png';


    
$this->load->library('upload'$config);
    
//add this
    
$this->upload->initialize($config);
if (!
$this->upload->do_upload(array('rajar_file','playlist_file','map_file''logo_file'))){
        $error 
$this->upload->display_errors();
        echo 
"[removed]alert($error);[removed]";
    
}else{
        $data 
= array('upload_data' => $this->upload->data(array('rajar_file','playlist_file','map_file''logo_file')));
        
        
$rajar_file_name $upload_data['rajar_file']['file_name'];
        
$rajar_full_file_path $path_to_uploads.'/'.$rajar_file_name;
        
         
$playlist_file_name $upload_data['playlist_file']['file_name'];
        
$playlist_full_file_path $path_to_uploads.'/'.$playlist_file_name;
        
         
$map_file_name $upload_data['map_file']['file_name'];
        
$map_full_file_path $path_to_uploads.'/'.$map_file_name;
        
         
$logo_file_name $upload_data['logo_file']['file_name'];
        
$logo_full_file_path $path_to_uploads.'/'.$logo_file_name;
    
}

// run validation
        
if ($this->validation->run() == FALSE){
            $data[
'message''';
        
}else{
            
// save data
            
$station = array('name' => $this->input->post('name'),
                            
'rajar' => $rajar_full_file_path,
                            
'playlist' => $playlist_full_file_path,
                            
'map' => $map_full_file_path,
                            
'logo' => $logo_full_file_path    );
            
$id $this->stationModel->save($station);
            
            
// set form input name="id"
            
$this->validation->id $id;
            
            
// set user message
            
$data['message''<div class="success">add new station success</div>';
        
}
        
          $this
->template->set('title''Admin - Add New Station!');
      
$this->template->load('admin/template''admin/stationEdit'$data);
      
     
    

After the form is submitted I get the following errors…

Message: Undefined variable: rajar_full_file_path
Message: Undefined variable: playlist_full_file_path
Message: Undefined variable: map_full_file_path
Message: Undefined variable: logo_full_file_path

Am I being daft, I cant figure it out?

Thanks
Dan

Profile
 
 
Posted: 23 July 2010 02:17 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Total Posts:  1
Joined  07-23-2010

Well, I found this solution so cool, but I wonder: What about the new security patch, made at version 1.7.2? Do you bear in mind this? Could you update this library according to the new Upload class published at the official site of Codeigniter?


Link at the patch: New security patch

Profile
 
 
Posted: 04 January 2011 09:30 AM   [ Ignore ]   [ # 19 ]  
Summer Student
Avatar
Total Posts:  25
Joined  11-01-2010

love this topic

Profile
 
 
Posted: 10 February 2011 08:44 AM   [ Ignore ]   [ # 20 ]  
Summer Student
Total Posts:  2
Joined  02-10-2011

Easy way to multiple files upload

part of view

<input type="file" name="image[]" /> 

part of controller content

<?php
    
// Image
    
$config['upload_path'$path.'images/';
    
$config['allowed_types''gif|jpg|png';
    
$config['file_name''screenshot';
    
$config['max_size''1024';
    
$config['overwrite'true;

    
$this->load->library('upload'$config);
    
// RE-SERIALIZE $_FILES ARRAY
    
foreach($_FILES['image'as $key => $file)
    
{
        $i 
0;
        foreach (
$file as $item
        
{
            $data[$i][$key] 
$item;
            
$i++;
        
}
    }
    
// END RE-SERIALIZE
    //print_r($_FILES);die; // see the real income data
    //print_r($data); die; // serialized data
    
$file ''// reset
    
$_FILES $data// re-declarate
    
for($j=0;$j<count($data);$j++)
    
{
        $config[
'file_name''image_'.$j;
        
$this->upload->initialize($config); 
        if(
$this->upload->do_upload($j)){
            $file 
$this->upload->data();
        
}
    } 

CodeIgniter v.1.7.3

Profile
 
 
Posted: 20 May 2011 11:52 PM   [ Ignore ]   [ # 21 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-18-2011

The filetype you are attempting to upload is not allowed.

$config['allowed_types''gif|jpg|png'

Im upload png files, why coming this kind error have i missed something?

Profile
 
 
Posted: 21 May 2011 05:51 AM   [ Ignore ]   [ # 22 ]  
Summer Student
Total Posts:  2
Joined  02-10-2011

Check function from system/libraries/Upload.php

/**
     * Verify that the filetype is allowed
     *
     * @access    public
     * @return    bool
     */    
    
function is_allowed_filetype() {
        
if (count($this->allowed_types) == OR ! is_array($this->allowed_types))
        
{
            $this
->set_error('upload_no_file_types');
            return 
FALSE;
        
}

        
if (in_array("*"$this->allowed_types))
        
{
            
return TRUE;
        
}

        $image_types 
= array('gif''jpg''jpeg''png''jpe');

        foreach (
$this->allowed_types as $val)
        
{
            $mime 
$this->mimes_types(strtolower($val));

            
// Images get some additional checks
            
if (in_array($val$image_types))
            
{
                
if (getimagesize($this->file_temp) === FALSE)
                
{
                    
return FALSE;
                
}
            }

            
if (is_array($mime))
            
{
                
if (in_array($this->file_type$mimeTRUE))
                
{
                    
return TRUE;
                
}
            }
            
else
            
{
                
if ($mime == $this->file_type)
                
{
                    
return TRUE;
                
}
            }
        }

        
return FALSE;
    
Profile
 
 
Posted: 24 May 2011 08:29 AM   [ Ignore ]   [ # 23 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-18-2011

smile You idea is not work for me! but im learn some from you! Im settled! Thank you for helping!

Profile
 
 
Posted: 24 May 2011 05:27 PM   [ Ignore ]   [ # 24 ]  
Summer Student
Total Posts:  1
Joined  05-24-2011

Yes - that’s ok

Profile
 
 
Posted: 08 May 2012 08:35 AM   [ Ignore ]   [ # 25 ]  
Grad Student
Avatar
Rank
Total Posts:  70
Joined  06-12-2011

This helper make easy use array names for upload files with array names.

Example:

In view

<form...
<
input type="file" name="files[]">
<
input type="file" name="files[]">
...
</
form

In controller

load->helper('upload');
multifile_array();
foreach (
$_FILES as $file => $file_data)
  
$this->upload->do_upload($file); 

Download:
http://porquero.blogspot.com/2012/05/codeigniter-multifilearray-upload.html

 Signature 

Web developer with open source soul
Blog: porquero.blogspot.com

Profile
 
 
   
2 of 2
2