[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