Welcome Guest, Not a member yet? Register   Sign In
Validating multiple inputs (File Upload Library)
#1

How can I validate two inputs using the CodeIgniter's File Upload Library?

I have two inputs
Code:
<input type="file" name="cover">
<input type="file" name="images[]" multiple>


I did try this one
PHP Code:
if( ! $this->upload->do_upload('cover') || ! $this->upload->do_upload('images[]') ) {
 
   die($this->upload->display_errors());

} else {
 
   var_dump($this->upload->data('file_name'));die();


...but it always displays "You did not select a file to upload."
Reply
#2

I recommend taking a look at Avenirer's solution:
http://avenir.ro/my_upload-extension-all...e-uploads/
Reply
#3

Basic looping to achieve multiple uploads might look something like this:


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

$files $_FILES;
$upload_count count$_FILES['userfile']['name'] );
for( 
$i 0$i $upload_count$i++ )
{
    $_FILES['userfile'] = [
        'name'     => $files['userfile']['name'][$i],
        'type'     => $files['userfile']['type'][$i],
        'tmp_name' => $files['userfile']['tmp_name'][$i],
        'error'    => $files['userfile']['error'][$i],
        'size'     => $files['userfile']['size'][$i]
    ];

    $init_config['file_name'] = str_replace'.'''microtime(TRUE) ) . '.jpg';

    $this->upload->initialize$init_config );
    
    if
$this->upload->do_upload() )
    {
        //...
    }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB