2012-11-07 17 views
2

我想用jshelper製作上傳文件。在CakePHP 2.2.1中使用jshelper上傳文件

筆者認爲:

<?php echo $this->Form->create('Form', array(
    'inputDefaults' => array(
    'format' => array('before', 'error', 'label', 'between', 'input', 'after'),), 
    'enctype' => 'multipart/form-data' 
)); 
echo $this->Form->input('Form.file', array('type' => 'file', 'id'=>'file')); 
$this->Js->get('#file')->event(
    'update', 
    $this->Js->request(
     array('controller' => 'ControllerForm','action' => 'actionForm'), 
     array(
     'async' => true, 
     'method' => 'post', 
     'dataExpression'=>true, 
     'data'=> $this->Js->serializeForm(array(
      'isForm' => false, 
      'inline' => true, 
      )) 
     ) 
)); 
echo $this->Js->writeBuffer(); 
echo $this->Form->end(); 
?> 

在我的控制器:

public function actionForm(){ 
    debugger::dump($this->data); 
} 

但是debugger::dump輸出空數組。

+2

調試思路:您是否在瀏覽器控制檯中收到任何JS錯誤? CakePHP生成的JS的外觀如何?請求是否實際發送?請求主體包含什麼內容? –

+0

不直接回答你的問題,但CakePHP上傳插件可能是一種更簡單的方法來實現相同的功能 – baordog

回答

0

因爲我知道你不能使用ajax發送文件(包括Chrome中的xhrRequestObject2)。首先在服務器端檢查數據實例調試($ _ FILES),但是由於我寫的是空的。使用舊的好iframe將數據發送到服務器。