How to display image and video from folder using PHP or Codeigniter

How to display image and video from folder using PHP or Codeigniter

You need to create a directory for upload image and videos.This tutorial will show directory path is template/uploads/.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>template/css/bootstrap.min.css">
<script src="<?php echo base_url(); ?>template/js/jquery.min.js"></script>
<script src="<?php echo base_url(); ?>template/js/bootstrap.min.js"></script>
<style>
.img{
   padding:10px;
}
</style>
</head>
<body>

<div class="col-md-12 col-xs-12 col-sm-12">
    <div class="row">
        <div class="col-xs-12 col-md-12 col-sm-12">
            <h3 class="main-title text-center">  How to display image and video from folder using PHP or Codeigniter </h3>
        </div>
        <div class="col-md-12 col-sm-6 col-xs-12">
            <?php $files = glob("template/uploads/*.*");
 for ($i=0; $i<count($files); $i++) {
 // $i mean to start first files names.
                   $cnum = $files[$i];
                   $aaa = base_url().$cnum;  ?>
   <div class="col-md-3 col-sm-6 col-xs-12">  
<?php if (preg_match('/(\.jpg|\.png|\.bmp|\.jpeg|\.gif|\.tiff)$/i', $aaa)) {
              echo '<a href="#" target="_blank"><img class="img" width="100%" height="165" src="'.base_url().$cnum.'" /></a><br />';
             } else{
             echo '<video width="100%" height="160" controls>
                   <source src="'.base_url().$cnum.'" /><br />
                   </video>
 ';  }   ?>
          </div>
           <?php } ?>                   
                           
        </div>
     <div class="clearfix"></div>
</div>
</div>
</body>
</html>




Comments

Popular posts from this blog

Profile Form in Codeigniter with Image upload and Validation

Multi Item Slider in Codeigniter using JQuery

Category Filter in Codeigniter