2013-02-11 74 views
1

我在CakePHP中使用jquery uploadify,並且我遇到了$ _SESSION的問題,因爲我有下面的動作接收用戶ID $ this-> request-> params [ 'named'] ['uid']問題是,啓用uploadify的操作會執行兩次,但第二個數據$ this-> request-> params ['named'] ['uid']會丟失。Uploadify正在執行的動作運行兩次

以下是爲了更好理解而簡化的代碼。

FilesController.php /指數**運行兩次

public function index() { 
     $id = $this->request->params['named']['uid']; 
     $us = $this->User->findById($id)['User']; 
     $dir = UPLOAD_DIR . $us['id'] . '/'; 
     CakeSession::write('Files.atual', $dir); 
     $this->set('u', $us); 
     //$this->autoRender = false; 
} 

查看/元/ up.ctp //啓用Uploadify

<?php $timestamp = time(); ?> 
    $(function() { 
     $('#file_upload').uploadify({ 
      'formData'  : { 
       'timestamp' : '<?php echo $timestamp; ?>', 
       'token'  : '<?php echo md5('unique_salt' . $timestamp); ?>' 
      }, 
      'swf'  : '<?= $this->request->webroot; ?>uploadify.swf', 
      'preventCaching' : false, 
      'uploader' : '<?= $this->request->webroot; ?>uploadify.php?session_id=<?php echo(session_id()); ?>', 
      'buttonClass' : 'button icon-paperclip', 
      'buttonText' : 'Enviar Arquivos', 
      'onUploadSuccess' : function(file, data, response) { 
       $('.files-icons').load('<?= $this->request->webroot; ?>files/reload/<?= $u['id'] ?>'); 
      } 
     }); 
    }); 

回答

0

到您的上傳動作的雙重請求由錯誤引起的在uploadify的button_background_url屬性中。您可以設置其停止額外的請求在您的.uploadify配置設置這對你的行動正在作出自己的背景圖片:

'button_image_url': '/img/cake.icon.png', 

只是作爲一個例子。您可能希望將其設置爲空或其他背景圖像。