2009-07-28 40 views
0

我想在上傳視頻(* .flv格式)時在我的applciation中顯示動態進度條。我在網上搜索了2個多小時,但我找不到任何教程來指導我完成這個過程。Zend_Progressbar + JQuery +上傳視頻

我到目前爲止有:

  • 腳本上傳視頻
  • 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在一起,實現了動感的上傳進度的簡單方法?

+0

你介意發佈你的解決方案嗎?我試圖達到同樣的目的。 – Andrew 2009-12-14 21:42:12

回答

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); 
    } 
}