CodeIgniter - File Upload

CodeIgniter - File Upload

CodeIgniter - File Upload

Using the File Uploading class, we can upload files, as well as limit the type and size of the uploaded file. Follow the steps shown in this example to understand the file upload process in CodeIgniter.

example

Copy the following code and save it to application/view/Upload_form.php .

 

  

     

  

        

  

     

     

                 

     

        

        

        

     

                 

  

        

Copy the code below and save it in application/view/Upload_success.php

 

  

     

  

        

   

     

Your file was successfully uploaded!

 

                 

     

            

            

    • :

            

           

                     

         

     

      

            

    Copy the code below and save it to application/controllers/Upload.php . Create a folder " uploads " in the root of CodeIgniter i.e. in the parent directory of the application folder.

    Make the following change in the route file in application/config/rout.php and add the following line to the end of the file.

    $route['upload'] = 'Upload';

    Now let's execute this example by visiting the following URL in a browser. Replace yoursite.com with your URL.

    http://yoursite.com/index.php/upload

    This will produce the following screen −

    After successfully uploading the file, you will see the following screen −