cakephpcakephp-1.3cakephp-model

CakePHP Ajax form submission with File Upload


I am using cake PHP file upload with the AJAX form submit. But it is not wotrking. There is nothing in the $_FILES array. But When I use normal form submit, it is working fine without any issue. I am using the following code for form submit using AJAX

    echo $this->Form->create('AlbumDetail',array('enctype' => 'multipart/form-data','type'=>'file'));

    echo $form->input('Image',array("type" => "file"));  

    echo $ajax->submit('Add Album', array('url'=> array('controller'=>'album_details', 'action'=>'addalbum'), 'update' => 'album_update'));

While ,

echo $this->Form->create('AlbumDetail', array('enctype' => 'multipart/form-data', 'controller' => 'album_details', 'action' => 'addalbum', 'type' => 'file'));

echo $form->input('Image',array("type" => "file")); 

echo "<input name='submit' type='submit' value='Add Album'>";

is working without any problem and $_FILES array is returning values. Can anyone do a little help ...?


Solution

  • As mentioned by void0, you cannot post a file using Ajax. This similar question has some workarounds and suggested libraries.