在CakePHP 2.2.1中使用jshelper上传文件

时间:2012-11-07 08:56:39

标签: ajax cakephp file-upload

我正在尝试使用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输出空数组。

1 个答案:

答案 0 :(得分:0)

我知道你不能使用ajax发送文件(在Chrome中包含xhrRequestObject2)。首先在服务器端检查发布数据实时调试($ _ FILES),但是我写的是空的。使用旧的好iframe将数据发送到服务器。