Welcome Guest, Not a member yet? Register   Sign In
How to add some video gallery to your website,(made simple)
#1

[eluser]ebot[/eluser]
Hello to all,
after playing around with CI, i decided to post this:
a simple tutorials on how to create a video gallery tools like flowplayer 3.1.1:
lets start by first creating a database, lets say the name of database is:
videogallery:
here is our table called video :
Code:
CREATE TABLE IF NOT EXISTS `video` (
  `video_id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `author` text NOT NULL,
  `vid` text NOT NULL,
  `thumbnail` text NOT NULL,
  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`video_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

now lets create our model to communicate with the database
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class videoM extends Model{

  function videoM()
  {
   parent::Model();
  }

  //this function gets all the posts and paginates them
    function getVideos($offset=-1,$limit=10){
        $this->db->orderby('video_id','asc');
        if($offset!=-1){
            $this->db->offset($offset);
            $this->db->limit($limit);
        }
        return $this->db->get('video');
    }
  function newVideo($video, $data =array())
    {
     $this->load->helper('date');
     $thumbnail = base_url()."thumbs/video.jpg";
     $this->db->insert('video',array(
            'title'        => $this->input->post('name'),
            'author'    => 'Ebot Tabe Tabi' ,
            'vid'    => $video,
            'thumbnail'=>$thumbnail,
            'date'        => date("Y-m-d H:i:s"),
            
            
        ));
    }

    function getVideo($id)
    
    {
      $this->db->select("*");
      $this->db->where(array('video_id'=>$id));
      $query=$this->db->get('video');
      return $query->result();
    }

}
?>

then lets create our in the functions: (upload, get and play) controller to upload to file.
Code:
function videos($offset=0)
  {
    $data['title']="my videos ";
    //number of blog posts i wish to show per page
        //$this->load->library('pagination');
        $perpage=2;
        $data['perpage']=$perpage;
        $data['videos']=$this->videoM->getVideos($offset,$perpage);
        $allvideos=$this->videoM->getVideos();
        $data['totalNum']=$allvideos->num_rows();
        $data['offset']=$offset;
        $this->load->vars($data);
        $this->load->view('myvideos');
  }
  
  function play($video_id)
  {
    $data['title']="You are viewing with id:  ".$video_id;
    $data['video']=$this->videoM->getVideo($video_id);
    $data['Videocomments']=$this->videoM->getVideoComment($video_id);
    $data['Videocount']=$this->videoM->getVideoCommentCount($video_id);
    $this->load->view('videoPlay',$data);
  }

function uploadVideo()
  {
            $config['upload_path'] = './videos/';
            $config['allowed_types'] = 'flv|jpg|png|jpeg';
            $config['max_size']    = '50000';
            
            //form set up
            $rules['name']    = "required";
              
            $fields['name']  = 'name';  
              
            $this->validation->set_rules($rules);
            $this->validation->set_fields($fields);    
          
            
            // check whether form has been run and validates
            if ($this->validation->run() == FALSE)
            {
                
                $this->session->set_flashdata('notice','Your video was not been uploaded!');
                redirect('manage/addVideo');
            }
            //else yes so do upload
            else
            {
            $this->load->library('upload', $config);
                //if upload not success display errors
                if ( ! $this->upload->do_upload())
                {
                    $data['error'] = $this->upload->display_errors();
                    
                      $this->load->view('admin/addvideo', $data);      
                }
                //else do form insert, image upload and image resize!!
                else
                {        
                //upload data
                $data['upload_data'] = $this->upload->data();
                $image=$data['upload_data']['orig_name'];
                $this->videoM->newVideo($image, $_POST);  
        $this->session->set_flashdata('message','Your video has been uploaded');
                redirect('manage/video');
                
                }      
            }              
  }
for you to be able to upload flv file get to the mime.php file in the system/application/config folder and add this in the mimes array:
Code:
'flv'=>array('video/x-flv', 'application/octet-stream')

i will post a reply for the view on this since the characters are going to exceed the required number
#2

[eluser]ebot[/eluser]
Here are the views both the one displaying the video and the on watching video playing:
Code:
<div class="videos">
&lt;?php if($videos->num_rows() == 0){
echo 'No video was found, please use \'Create a new video\' link above to add a new video';
}?&gt;

&lt;?php
    foreach($videos->result() as $postblogs){
       echo "<h2><a href='#'>".$postblogs->title."</a></h2>";?&gt;
        <i class="postinfo"><img src="&lt;?=base_url();?&gt;images/ico_auth.jpg" alt="Author" /> : &nbsp;&lt;?=$postblogs->author?&gt;</i>
        Date Posted : &nbsp;&lt;?=$postblogs->date?&gt;</i><br />
        <img >thumbnail;?&gt;" title="&lt;?=$postblogs->title;?&gt;"><br>
        <b class="post_end"><img src="&lt;?=base_url()?&gt;images/ico_link.jpg" alt="permalink" />
        <a >video_id?&gt;" title="&lt;?=$postblogs->title;?&gt;">Play this video</a>&nbsp;&nbsp;
        <img src="&lt;?=base_url()?&gt;images/ico_com.jpg" alt="Comment" width="18" height="13" />Comments(&lt;?=$this->videoM->getVideoCommentCount($postblogs->video_id);?&gt;)
        
        </b>
        &lt;?
        echo "<br />";
        echo "<br />";
        echo "<br />";
        echo "<br />";
        echo "<br />";
        
    }
?&gt;
&lt;?php
    //$this->load->library('pagination');
    $config['base_url'] = base_url().'myvideo/videos';
    $config['total_rows'] = $totalNum;
    $config['per_page'] = $perpage;
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
?&gt;
</div>

the view for watching the video
Code:
<div class="post">
<h1 style="color:#333333;">You're watching a video! ^_^<sup>?</sup></h1>

<br/>
<br/>

<br/>
&lt;?php foreach ($video as $field): ?&gt;
<h3>Title: &nbsp;&lt;?=$field->title;?&gt;</h3><br/>
<i class="postinfo"><img src="&lt;?=base_url();?&gt;images/ico_auth.jpg" alt="Author" /><sub style="font-size:8px;">Author</sub> : &nbsp;&lt;?=$field->author;?&gt;</i>
Date Posted:&nbsp;&lt;?=$field->date;?&gt;<br/>
<img src="&lt;?=base_url()?&gt;images/ico_com.jpg" alt="Comment" width="18" height="13" />Comments(&lt;?=$Videocount;?&gt;)
<br/>
<br/>
  [removed][removed]
     <a  
    >vid;?&gt;"  
    style="display:block;width:425px;height:300px;"  
    id="player">
    </a>
    [removed]
    flowplayer("player", "&lt;?=base_url();?&gt;flowplayer-3.1.1.swf");
    [removed]      
<br/>
<br/>

&lt;?php endforeach;?&gt;

for the player (flowplayer-3.1.1) whi you can get from : <a href="flowplayer.org">flowplayer</a>

if any problem or enquiries, please do drop me mail at ebot.tabi[at]gmail[dot]com or PM me
thanks
#3

[eluser]Sean Downey[/eluser]
Hi

I had to use this for the mime.php
Code:
'flv'    =>    array('video/flv', 'video/x-flv', 'application/octet-stream'),
#4

[eluser]patrik anders[/eluser]
Hi ebot first thanks for sharing the script.
i am busy with a site that uses XtraUpload v2 script.
i want to add a new function that allow users to browse the site videos or to have a list
with all videos that are uploaded in a list with video thumbil,info.

1-Can your script help me with creating the new function?
2-And If so how can i do it ?

Sorry if asking to much but i am a noobie.
I am hooping that you can help me ,and thanks again.
#5

[eluser]ebot[/eluser]
@patrik anders, i can help you out, but what type of function do you need? please email me at : ebot [dot] tabi [at] gmail [dot] com
#6

[eluser]kamal lamichhane[/eluser]
can u give the source code?
#7

[eluser]ebot[/eluser]
@kamal sure i can give you the source codes. PM me your email address or preferably contact me at ebot[dot]tabi[at]gmail[dot]com
#8

[eluser]kamal lamichhane[/eluser]
@EbotT my email is info[dot]lckamal[at]gmail[dot]com. thank u for your response.
#9

[eluser]amina[/eluser]
Someone could adapt this code for codeigniter 2.0. Because I need a video gallery. Thanks
#10

[eluser]InsiteFX[/eluser]
If you people want to include javascript just change the script to $cript




Theme © iAndrew 2016 - Forum software by © MyBB