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
#1

Every one knows although being very simple to use but very powerful framework, it is often hard to make multiple file upload work as desired with ease. There are some third party solutions but they are harder to implement or they are harder to tweak to make them work as desired.

So I would like to request as a suggestion that there should be a multiupload class that extends the upload class so that it uses multiupload class for multiple files and fall back to upload class automatically for single file. Or it could be upload class handle both single or multiple class.

I would like to suggest plupload be integrated for this.
Reply
#2

I Agree.

But i suggest a simple implementation and a advanced with plupload.
Reply
#3

Although not essential, it would make life a lot easier =)
Reply
#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
#5

(10-26-2014, 08:01 PM)orionstar Wrote: 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.

thank you sharing your codes.
Plupload is great tool and i want it work with codeigniter easily.
Reply
#6

As for me framework should framework. In CI, is not no any pattern generator or something else like that. This concern javascript (front-end) development .
Reply




Theme © iAndrew 2016 - Forum software by © MyBB