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
    • 222
    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

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

    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.

    1. public function upload()
    2. {
    3. print_r($this->request->data); die;
    4. }

    this will give us something like this:

    1. Array
    2. (
    3. [Model] => Array
    4. (
    5. [files] => Array
    6. (
    7. [0] => Array
    8. (
    9. [name] => MY.jpg
    10. [type] => image/jpeg
    11. [tmp_name] => // your temp path
    12. [error] => 0
    13. [size] => 1826587
    14. )
    15. [1] => Array
    16. (
    17. [name] => YOU.jpg
    18. [type] => image/jpeg
    19. [tmp_name] => //your temp path
    20. [error] => 0
    21. [size] => 1127346
    22. )
    23. )
    24. )

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: