Welcome Guest, Not a member yet? Register   Sign In
Poll: Do you think CI should have multiupload feature without having to use third party codes?
You do not have permission to vote in this poll.
Yes
85.19%
23 85.19%
No
11.11%
3 11.11%
May be (Not Sure)
3.70%
1 3.70%
Total 27 vote(s) 100%
* You voted for this item. [Show Results]

Multiple file Upload without third party codes
#4

(This post was last modified: 10-27-2014, 04:16 AM by orionstar.)

If I remember correctly you can easily use CI's file uploader to work with multiple files, see below:

PHP Code:
$this->load->library('upload'$config);

// Cache the real $_FILES array, because the original
// will be overwritten soon :)
$files        $_FILES;
$file_count    count($_FILES['upload_field_name']['name']);

// Iterate over the $files array
for($i 0$i $file_count$i++)
{
    
// Overwrite the default $_FILES array with a single file's data
    // to make the $_FILES array consumable by the upload library
    
$_FILES['upload_field_name']['name']        = $files['upload_field_name']['name'][$i];
    
$_FILES['upload_field_name']['type']        = $files['upload_field_name']['type'][$i];
    
$_FILES['upload_field_name']['tmp_name']    = $files['upload_field_name']['tmp_name'][$i];
    
$_FILES['upload_field_name']['error']        = $files['upload_field_name']['error'][$i];
    
$_FILES['upload_field_name']['size']        = $files['upload_field_name']['size'][$i];

    if( ! 
$this->upload->do_upload('upload_field_name'))
    {
        
// Handle upload errors
        
        // If an error occurs jump to the next file
        
break;
    }
    else
    {
        
// Successfull file upload
    
}


And on the upload field you should add an extra attribute multiple="multiple".

UPDATE: If you want to enable the upload of a single file you should check $_FILES['upload_field_name']['name'] is_array, if not then you should go the usual way.
Reply


Messages In This Thread
RE: Multiple file Upload without third party codes - by orionstar - 10-26-2014, 08:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB