How to upload multiple images using codeigniter?

Abhijit Kumbhar

I'm trying to upload multiple image using codeigniter thats actually working fine, But I want to store images to specific directory. My directory structure is

uploads/real/

inside this directory I want to create one more directory with the name of userid so directory structure becomes

uplods/real/20

I added logic and written some code like below: Consider $path="real", and $userid="20"

function image_upload($path,$userid)
    {
        $basepath = "uploads/".$path;
        echo "base-path > ".$basepath;
        echo "<br>working-dir > ".getcwd();
        chdir($basepath);
        echo "<br>working-dir > ".getcwd();
        if(!file_exists($userid)){
            mkdir($userid);
            chdir($userid);
            echo "<br>Working-dir > ".getcwd();
            $filesCount = count($_FILES['image']['name']);
            echo "<br> FileCount > ".$filesCount;
            for($i = 0; $i < $filesCount; $i++){
                $_FILES['img']['name'] = $_FILES['image']['name'][$i];
                $_FILES['img']['type'] = $_FILES['image']['type'][$i];
                $_FILES['img']['tmp_name'] = $_FILES['image']['tmp_name'][$i];
                $_FILES['img']['error'] = $_FILES['image']['error'][$i];
                $_FILES['img']['size'] = $_FILES['image']['size'][$i];

                echo "<br>FILES-Array > <pre>";
                print_r($_FILES);
                echo "<pre>";

                $config['upload_path']= "/";
                $config['file_name']=$userid .$i. '.jpg';
                $config['allowed_types']= 'jpg|png';
                $config['max_size']= 2048;

                echo "<br>CONFIG-Array > <pre>";
                print_r($config);
                echo "<pre>";

                $this->load->library('upload', $config);
                $this->upload->initialize($config);

                if ( ! $this->upload->do_upload('img'))
                {
                    $error = array('error' => $this->upload->display_errors());
                    echo "<br>UPLOAD-ERROR > <pre>";
                    print_r($error);
                    echo "<pre>";
                }
                else
                {
                    $da = array('upload_data' => $this->upload->data());
                    echo "_________IMAGE UPLOADED_______";
                }
            }

        }else{
            echo "<br>Folder Exist ...";
        }
        die();

And Browser Output is :

base-path > uploads/real
working-dir > C:\wamp64\www\ob_03
working-dir > C:\wamp64\www\ob_03\uploads\real
Working-dir > C:\wamp64\www\ob_03\uploads\real\20
FileCount > 1
    FILES-Array >
Array
(
    [image] => Array
        (
            [name] => Array
                (
                    [0] => abhi.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => C:\wamp64\tmp\php336F.tmp
                )

            [error] => Array
                (
                    [0] => 0
                )

            [size] => Array
                (
                    [0] => 72125
                )

        )

    [img] => Array
        (
            [name] => abhi.jpg
            [type] => image/jpeg
            [tmp_name] => C:\wamp64\tmp\php336F.tmp
            [error] => 0
            [size] => 72125
        )

)
CONFIG-Array > 
Array
(
    [upload_path] => /
    [file_name] => 180.jpg
    [allowed_types] => jpg|png
    [max_size] => 2048
)
_________IMAGE UPLOADED_______

I'm not getting any error on printing print_r($error); But image is not uploaded to my directory WHY?

Mr. ED

Try using FCPATH for uploads sometimes works better.

FCPATH: Path to the front controller (this file) (root of CI)

$config['upload_path'] = FCPATH . 'uploads/real/18/';

Or try

$config['upload_path'] = './uploads/real/18/';

Make sure you set 0777 for image uploads folders.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Upload multiple images with codeigniter

From Dev

How to upload multiple files using codeigniter

From Dev

how to upload multiple images on codeigniter from single input fileds

From Dev

Upload multiple images using AFNetworking

From Dev

codeigniter form upload with images using ajax

From Dev

How to upload multiple file in codeigniter?

From Dev

Rails 4: How to upload multiple images using carrierwave

From Dev

How to upload multiple images in Django using Dropzone and saving path dynamically ?

From Dev

how do i upload multiple images using Multiparty Entity in Android

From Dev

How do I upload multiple images using multer in node js?

From Dev

How to upload 2 separate images in codeigniter

From Dev

How to set upload images limit in codeigniter 3

From Dev

How do I upload multiple images and text file in a single form with the different button in Codeigniter?

From Dev

How to display images using codeigniter

From Dev

Upload multiple images using AFNetworking in swift

From Dev

How to upload multiple files in codeigniter 3.0.1

From Dev

how to upload multiple images to a blog post in django

From Dev

how to upload video file in database using codeigniter

From Dev

How To upload file using Angularjs And codeigniter?

From Java

How to upload multiple images in Laravel using AWS bucket, and ignore if same image uploaded?

From Dev

How to upload multiple images at a time in s3 bucket using Node JS (Express)

From Dev

Multiple files upload in Codeigniter

From Dev

multiple file upload in codeigniter

From Dev

Codeigniter Multiple upload files

From Dev

How to upload images with cloud kit using swift?

From Dev

how to upload the images and save it to database using react

From Dev

Uploading multiple images in codeigniter?

From Dev

Uploading multiple images in codeigniter?

From Dev

Upload multiple images

Related Related

  1. 1

    Upload multiple images with codeigniter

  2. 2

    How to upload multiple files using codeigniter

  3. 3

    how to upload multiple images on codeigniter from single input fileds

  4. 4

    Upload multiple images using AFNetworking

  5. 5

    codeigniter form upload with images using ajax

  6. 6

    How to upload multiple file in codeigniter?

  7. 7

    Rails 4: How to upload multiple images using carrierwave

  8. 8

    How to upload multiple images in Django using Dropzone and saving path dynamically ?

  9. 9

    how do i upload multiple images using Multiparty Entity in Android

  10. 10

    How do I upload multiple images using multer in node js?

  11. 11

    How to upload 2 separate images in codeigniter

  12. 12

    How to set upload images limit in codeigniter 3

  13. 13

    How do I upload multiple images and text file in a single form with the different button in Codeigniter?

  14. 14

    How to display images using codeigniter

  15. 15

    Upload multiple images using AFNetworking in swift

  16. 16

    How to upload multiple files in codeigniter 3.0.1

  17. 17

    how to upload multiple images to a blog post in django

  18. 18

    how to upload video file in database using codeigniter

  19. 19

    How To upload file using Angularjs And codeigniter?

  20. 20

    How to upload multiple images in Laravel using AWS bucket, and ignore if same image uploaded?

  21. 21

    How to upload multiple images at a time in s3 bucket using Node JS (Express)

  22. 22

    Multiple files upload in Codeigniter

  23. 23

    multiple file upload in codeigniter

  24. 24

    Codeigniter Multiple upload files

  25. 25

    How to upload images with cloud kit using swift?

  26. 26

    how to upload the images and save it to database using react

  27. 27

    Uploading multiple images in codeigniter?

  28. 28

    Uploading multiple images in codeigniter?

  29. 29

    Upload multiple images

HotTag

Archive