0

我想在上传视频(*.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 来实现动态上传进度条?

4

1 回答 1

1

您可以进行长轮询(彗星)或短轮询(ajax)来达到预期的效果。对于前者,我建议在 iFrame 中发出请求,并让你的代码写出 JS,这些 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);
   }
}
于 2009-07-28T19:33:14.753 回答