Zend_Progressbar + JQuery +上传视频

时间:2009-07-28 17:21:00

标签: php javascript jquery zend-framework progress-bar

我想在上传视频(* .flv格式)时在我的应用中显示动态进度条。我在网上搜索了超过2个小时,但我找不到任何指导我完成这个过程的教程。

到目前为止我所拥有的:

  • 上传视频的脚本
  • jQuery库包含在
  • 部分中

但接下来该怎么办?以下是用于上传我使用的视频的控制器操作:

public function uploadPublicVideoAction()
{
    $request = $this->getRequest();
    $media = $this->_getTable('Media');

    $form = $this->_getForm('UploadPublicVideo',
                            $this->_helper->url('upload-public-video'));
    // if POST data has been submitted
    if ($request->isPost()) {
        // if the UploadPublicVideo form has been submitted and the submitted data is valid
        if (isset($_POST['upload_public_video']) && $form->isValid($_POST)) {

            $data = $form->getValues();
            $data['user_id'] = $this->view->identity->id;

            $ext = end(explode('.', $form->video->getFileName()));

            $dbTrans = false;

            try {

                $db = $this->_getDb();
                $dbTrans = $db->beginTransaction();

                $data['type'] = 'video';
                $data['status'] = 'public';
                $paths = $media->add($data, $ext);

                if (file_exists($paths[0])) {
                   unlink($paths[0]);
                }
                if (file_exists($paths[1])) {
                   unlink($paths[1]);
                }

                // add filter for renaming the uploaded photo
                $form->video->addFilter('Rename',
                                        array('target' => $paths[0],
                                              'overwrite' => true));

                // upload the video
                $form->video->receive();

                // create a thumbnail
                //$this->_helper->FlvThumbnail($path[0], $path[1]);

                $db->commit();

                $form->reset();

                $this->view->success = 'Public video successfully uploaded';

            } catch (Exception $e) {
                if (true === $dbTrans) {
                    $db->rollBack();
                }
                $this->view->error = $e->getMessage();
            }

        }
    }

    $this->view->headTitle('Upload Public Video');
    $this->view->form = $form;
}

有人能告诉我一个简单的方法,一起使用Zend_Progressbar和jQuery来实现动态上传进度条吗?

1 个答案:

答案 0 :(得分:1)

您可以执行长(彗星)或短轮询(ajax)以达到所需效果。对于前者,我建议在iFrame中发出请求并让你的代码写出JS,它们会在它们进入时执行,后者只需执行以下操作:

var pollingId = window.setInterval(poll, 250);
function poll(){
   //make an AJAX request, do something with it (like update your progress bar).
   if(done){
      window.clearInterval(pollingId);
   }
}