Upload video file in php with codeigniter framework

Upload video file in php with codeigniter framework its easy steps to make upload file functionality in codeigniter first create a file in

Step 1 application/controller/Fileupload.php

and  this code in the file


<?php

// create a file in controller with your class name first letter must be a capital in filename

class Fileupload extends CI_Controller {

        public function __construct()
        {
                parent::__construct();
                //load helper to load a forms
                $this->load->helper(array('form', 'url'));
                $this->load->model('emp_model');

        }

        public function index()
        {  //load a html file

          $this->load->view('pages/fileupload', array('error' => ' ' ));
        }

        public function do_upload()
        {
          //Get a file Here set a upload path and type of file if you set * then you will allow to upload all type of file
          //video,images,document,sql file etc
        
                $config['upload_path']          = './img/';
               $config['allowed_types']        = 'mp4';
                $config['max_size']             = 0;
                $config['max_width']            = 5024;
                $config['max_height']           = 2068;

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

                if ( ! $this->upload->do_upload('userfile'))
                {
                        $error = array('error' => $this->upload->display_errors());

                        $this->load->view('pages/fileupload', $error);
                }
                else
                {
                  //here pass value to get a info of uploaded data
                        $data = array('upload_data' => $this->upload->data());

                        $this->load->view('pages/file_upload_success', $data);
                }
        }
}
?>


Step 2 create file application/view/pages/fileupload.php

and add this code

<html>
<head>
<title>Upload Form</title>
</head>
<body>
<!-- Here we create a form to submit a file  fileupload is class/file name and do_upload is a function  -->

<?php echo $error;?>

<?php echo form_open_multipart('fileupload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</form>

</body>

</html>

Step 2 create file application/view/pages/file_upload_success.php



<html>
<head>
<title>Upload Form</title>
</head>
<body>

<h3>Your file was successfully uploaded!</h3>

<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

<p><?php echo anchor('fileupload', 'Upload Another File!'); ?></p>

</body>

</html>

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...