How to add some video gallery to your website,(made simple) - El Forum - 07-06-2009
[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
How to add some video gallery to your website,(made simple) - El Forum - 07-06-2009
[eluser]ebot[/eluser]
Here are the views both the one displaying the video and the on watching video playing:
Code: <div class="videos">
<?php if($videos->num_rows() == 0){
echo 'No video was found, please use \'Create a new video\' link above to add a new video';
}?>
<?php
foreach($videos->result() as $postblogs){
echo "<h2><a href='#'>".$postblogs->title."</a></h2>";?>
<i class="postinfo"><img src="<?=base_url();?>images/ico_auth.jpg" alt="Author" /> : <?=$postblogs->author?></i>
Date Posted : <?=$postblogs->date?></i><br />
<img >thumbnail;?>" title="<?=$postblogs->title;?>"><br>
<b class="post_end"><img src="<?=base_url()?>images/ico_link.jpg" alt="permalink" />
<a >video_id?>" title="<?=$postblogs->title;?>">Play this video</a>
<img src="<?=base_url()?>images/ico_com.jpg" alt="Comment" width="18" height="13" />Comments(<?=$this->videoM->getVideoCommentCount($postblogs->video_id);?>)
</b>
<?
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
}
?>
<?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();
?>
</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/>
<?php foreach ($video as $field): ?>
<h3>Title: <?=$field->title;?></h3><br/>
<i class="postinfo"><img src="<?=base_url();?>images/ico_auth.jpg" alt="Author" /><sub style="font-size:8px;">Author</sub> : <?=$field->author;?></i>
Date Posted: <?=$field->date;?><br/>
<img src="<?=base_url()?>images/ico_com.jpg" alt="Comment" width="18" height="13" />Comments(<?=$Videocount;?>)
<br/>
<br/>
[removed][removed]
<a
>vid;?>"
style="display:block;width:425px;height:300px;"
id="player">
</a>
[removed]
flowplayer("player", "<?=base_url();?>flowplayer-3.1.1.swf");
[removed]
<br/>
<br/>
<?php endforeach;?>
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
How to add some video gallery to your website,(made simple) - El Forum - 08-26-2009
[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'),
How to add some video gallery to your website,(made simple) - El Forum - 10-30-2009
[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.
How to add some video gallery to your website,(made simple) - El Forum - 12-13-2009
[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
How to add some video gallery to your website,(made simple) - El Forum - 10-30-2010
[eluser]kamal lamichhane[/eluser]
can u give the source code?
How to add some video gallery to your website,(made simple) - El Forum - 11-03-2010
[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
How to add some video gallery to your website,(made simple) - El Forum - 11-15-2010
[eluser]kamal lamichhane[/eluser]
@EbotT my email is info[dot]lckamal[at]gmail[dot]com. thank u for your response.
How to add some video gallery to your website,(made simple) - El Forum - 01-25-2012
[eluser]amina[/eluser]
Someone could adapt this code for codeigniter 2.0. Because I need a video gallery. Thanks
How to add some video gallery to your website,(made simple) - El Forum - 01-25-2012
[eluser]InsiteFX[/eluser]
If you people want to include javascript just change the script to $cript
|