AJAX HTML Javascript jQuery PHP Example MORE
Need a Website Or Web Application Or Any Help.Contact Us: +91 9437911966 (Whatsapp) Note: Paid Service

How to view file in PHP MVC with example


In this example we using Models, Views, Controller Structure for upload multiple file.

Image table

Here is the Controller file hello.php which inside controllers folder

controllers/hello.php

<?php
class Hello extends Controller {

	function __construct() {
		parent::__construct();
	}
    function view_file(){
		$this->view->content = $this->model->get_files();
        $this->view->render('hello/view_files');
	}
}
?>

models/hello_model.php

hello_model.php

<?php
class Hello_Model extends Model
{
	public function __construct()
	{
		parent::__construct();
		
	}
    public function get_files()
    {
       return $this->db->select("SELECT * FROM `image_table`");
    }
}
?>

Here is the view file upload.php which inside views folder contains the form.

views/hello/upload.php

<!DOCTYPE html>
<html>
<body>

<?php
	foreach($this->content as $row){
		?>
<img src="<?php echo URL;?>public/uploads/<?php echo $row['image'];?>" height="100px" width="100px">
<?php
	}
?>
</html>
</body>
Path: localhost/project_folder_name/view_folder_name/view_filename Example: localhost/mvc/hello/view_file