Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • CakePHP Multiple File Upload

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 217
    Comment on it

    Hello readers, if you are looking for a code to upload multiple file in CakePHP where user can upload more than one image through input browse box, then your are in a right place i.e findnerd.com.

    Here is a quick tutorial which will explain how to use HTML5 multiple file upload tag with CakePHP.

    HTML 5 Multiple fle Tag: <input name = 'upload[]' type = 'file multiple'>

    Now, we need to use CakePHP form helper in our ctp file to achieve multiple file upload which is equivalent to HTML 5 multiple file tag.

    Upload.ctp

    <?php
    echo $this->Form->create('User', array('type' => 'file'));
    echo $this->Form->input('files.', array('type' => 'file', 'multiple'));
    echo $this->Form->end('Upload');
    ?>

    Adding a dot . like file. in the end of the name shows all the images selected.
    Suppose, if you upload two files  MY.jpg & YOU.jpg

    Now, use $this->request->data property in your controller function.

    public function upload()
     {
      print_r($this->request->data); die;
     }

    this will give us something like this:

    Array
    (
        [Model] => Array
            (
                [files] => Array
                    (
                        [0] => Array
                            (
                                [name] => MY.jpg
                                [type] => image/jpeg
                                [tmp_name] => // your temp path
                                [error] => 0
                                [size] => 1826587
                            )
                        [1] => Array
                            (
                                [name] => YOU.jpg
                                [type] => image/jpeg
                                [tmp_name] => //your temp path
                                [error] => 0
                                [size] => 1127346
                            )
            )
    )

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: