Hey guys,

I'm having the most toughest time of my life to figure out a way to upload video files using PHP.
I am able to upload images but not video files or zip files. I haven't put any file extension check right now.
Here is my code, will you be able to find where i went wrong?

I am using CodeIgniter. Is there anything i need to do in CI to make this happen?

<form action="<?php echo current_url()?>" method="POST" enctype="multipart/form-data">
    <input name="files[]" type="file" multiple required>
    <input type="submit" name="form_submit" value="Upload Selected Items">

    public function add(){

        $data['title']="Upload New Media";
        $data['subtitle']="Upload Media & Add Info";
            foreach($_FILES as $file){
                    /* for debugging */
                        echo $file['name'][$i]."<br>";
                        echo $file['type'][$i]."<br>";
                        echo $file['tmp_name'][$i]."<br>";
                        echo $file['error'][$i]."<br>";
                        echo $file['size'][$i]."<br><br>";


                        $tempFile = $file['tmp_name'][$i];
                        $fileName = $file['name'][$i];
                        $targetPath = getcwd().'/uploads/'.$data['userid'].'/';
                        if(!file_exists($targetPath)) {mkdir($targetPath);}
                        $targetFile = $targetPath.substr(uniqid(rand()),0,90).'.'.end($ext);
                        if(move_uploaded_file($tempFile, $targetFile)==true){
                            echo "done!";



Recommended Answers

All 10 Replies

YOur code shall be like this are you using windows you need to download FFMpeg.exe because this code will work in Linux.If you are using Linux server, Use print phpinfo() function to check whether your hosting server has FFmpeg installed or you need it to be installed.

$file    = 'video_file';
$config['upload_path']  = './video_folder/';
$config['allowed_types']  = 'mov|mpeg|mp3|avi';
$config['max_size']  = '50000';
$config['max_width']    = '';
$config['max_height']    = '';

$this->load->library('upload', $config);

 // If there is any error
 $err_msgs .= 'Error in Uploading video '.$this->upload->display_errors().'<br />';
 $data=array('upload_data' => $this->upload->data());
 $video_path = $data['upload_data']['file_name'];
  $directory_path   = $data['upload_data']['file_path'];
 $directory_path_full      = $data['upload_data']['full_path'];
 $file_name   = $data['upload_data']['raw_name'];

 // ffmpeg command to convert video

 exec("ffmpeg -i ".$directory_path_full." ".$directory_path.$file_name.".flv"); 

// $file_name is same file name that is being uploaded but you can give your custom video name after converting So use something like myfile.flv.

 /// In the end update video name in DB 
 $array = array(
  'video' => $file_name.'.'.'flv',
 $this->db->where('id',$id); // Table where you put video name
 $query = $this->db->update('user_videos');  

Hey i forgot to mention. I am using windows 64-bit and running the scripts on WAMP with PHP 5.5.12!

First tell me what is your purpouse .Is the purpouse learning to write a code or you have any project to accompalish.Or you just want to see video on your site.

Just to learn writing code on Codeigniter! I was able to upload images but was wondering why am not able to upload videos just like i upload images. I was able to upload videos on wamp long time back! Thought i had gone wrong somewhere with my code!

Have you looked upon the above code ?

    //echo "hi..";
    $insert="insert into tbl_video values('','$dest','1')";

    <script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>

    $("#upfile1").click(function () {

function msg()
<body onmouseleave="msg();" onmouseover="msg1()">
<form method="post" enctype="multipart/form-data">
<!--<input type="file" name="video_file"/>-->
<img src="images.jpeg" id="upfile1" style="cursor:pointer" height="30" width="120"/>
<input type="file" id="file1"  name="video_file" style="display:none" />
<input type="submit" name="upload" value="Submit"/>

$select_video=mysql_query("select * from tbl_video");
    <embed src="<?php echo $fetch_video['video'];?>" autostart="false" volume="true"/>

<?php //echo $fetch_video['video'];?>
<?php } ?>

use this code that definately help you

@Hiren2927 mysql is deprecated.It will give an error we shall use mysqli or PDO

u can make changes in above code code is perfect in xampp u just have make some changes like mysqli...etc than u,ll able to upload video try it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.