Hi,
I’m trying to create a form to save data into db. one of this data is image ( binary data ).
So I have try two approach.
-
I request it on controller and it worked.
-
I request it use ajax, but there is some thing wrong, when i saw from firebug.
on the post tab there is no binary data is sent into server.
This is a spot of my code :
this is locate on my view, i take an approach from http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/ ( Thanks Zac, it help me a lot <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' /> )
<?php echo CHtml::ajax(array(
'url'=>array('SDMPerson/create'),
'data'=> "js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if (data.status == 'failure')
{
$('#sdmDialog div#divForForm').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#sdmDialog div#divForForm form').submit(addSdm);
}
else
{
$.fn.yiiGridView.update('sdmperson-grid');
$('#sdmDialog div#divForForm').html(data.div);
setTimeout(\"$('#sdmDialog').dialog('close') \",2000);
}
} ",
))?>;
return false;
This is a piece code locate on my controller, i used it on NON AJAX request ( worked ).
I want to add some NOTE HERE : on ajax request i just can't save binary data into db, but another data can saved correctly .
$img=CUploadedFile::getInstance($model,'photoImg');
if($img !== null && !$img->getHasError())
$model->photo = file_get_contents($img->getTempName());
Thanks a lot
Hope anyone can help me , or give suggestion.
God Bless You