代码之家  ›  专栏  ›  技术社区  ›  Richard Knop

Zend_ProgressBar+jQuery+上传视频

  •  0
  • Richard Knop  · 技术社区  · 15 年前

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

    到目前为止我有:

    • 上载视频的脚本
    • 包含在该部分中的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来实现动态上载ProgressBar吗?

    1 回复  |  直到 15 年前
        1
  •  1
  •   Knickerless-Noggins    15 年前

    您可以执行长轮询(Comet)或短轮询(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);
       }
    }