[eluser]codeplay[/eluser]
hello there!
i have this upload form which uploads a video to the server, encodes it (using FFMPEG), and puts it onto Amazon S3.
i have a jquery progressbar which shows the progress of the uploading+encoding process, by using ajax to do a GET request and to update it every 1/2 a second.
im setting the progress variable after each stage of the process.
the problem is it doesnt work as the data that is returned is always 'nothing'.
i just cant see what im doing wrong and whether the technique im using would work.
heres some of my code:
header.php (view)
Code:
function beginUpload() {
var i = setInterval(function() {
$.get('<?php echo base_url(); ?>upload/progress', function(data) {
$( "#uploadprogressbar" ).progressbar( "option", "value", parseInt(data) );
});
}, 500);
}
$(document).ready(function(){
$("#uploadform").submit(function () {
beginUpload();
});
$("#uploadprogressbar").progressbar({value:0});
....
upload.php (controller)
Code:
class Upload extends Controller {
public $progress;
function Upload()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('Video');
}
function index()
{
$this->processupload();
}
function processupload()
{
$data['page_title'] = "Upload";
//validation stuff omitted
$this->form_validation->set_error_delimiters('<div class="form_error">', '</div>');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header', $data);
$this->load->view('upload');
$this->load->view('footer');
} else {
$uniq_id = time();
$this->setprogress(10);
$error = $this->do_upload($uniq_id);
if($error == "")
{
$this->setprogress(90);
$video_data = array(
'user_id' => $user_id,
'sport_cat' => $this->input->post('sport_cat'),
'competition_cat' => $this->input->post('competition_cat'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'tags' => $this->input->post('tags'),
'uniq_id' => $uniq_id
);
$this->Video->add($video_data);
$this->setprogress(100);
redirect(base_url());
} else {
$data['uploaderror'] = '<div class="form_error">'.$error.'</div>';
$this->load->view('header', $data);
$this->load->view('upload', $data);
$this->load->view('footer');
}
}
}
function do_upload($uniq_id)
{
$config['upload_path'] = 'assets/videos/temp/';
$config['allowed_types'] = 'wmv';
$config['max_size'] = '50000';
$config['file_name'] = $uniq_id.".wmv";
$this->load->library('upload', $config);
$error = "";
$this->setprogress(20);
if ( ! $this->upload->do_upload('upload_video'))
{
$error = $this->upload->display_errors();
//print_r($config);
}
else
{
$this->setprogress(30);
$data = $this->upload->data();
$this->setprogress(40);
echo exec("ffmpeg -i "."assets/videos/temp/".$data['file_name']." -ar 22050 -ab 32 -f flv -s 480x360 "."assets/videos/temp/".$data['raw_name'].".flv");
$this->setprogress(60);
//include the S3 class
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'xxx');
if (!defined('awsSecretKey')) define('awsSecretKey', 'xxx');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
//move the file
if (!$s3->putObjectFile("assets/videos/temp/".$data['raw_name'].".flv", "xxx", $data['raw_name'].".flv", S3::ACL_PUBLIC_READ)) {
$error ="Something went wrong while uploading your file...";
}
$this->setprogress(80);
}
return $error;
}
function setprogress($value)
{
$this->progress = $value;
}
function progress()
{
echo $this->progress;
}
.........
all help and advice will be greately appreciated! thank you