I’ve been looking at this Uploadify extension and it definitely looks a bit better than the other one in the extensions section. I’ve run into a problem though, with overriding the event for Uploadify.
Example:
Try to add an ‘onOpen’ or ‘onComplete’ event to your widget instanciation…for me, this isn’t working, I see the key/values showing up in the outputted javascript at the bottom of the page, but the events are not making it back to Uploadify, or Uploadify doesn’t know how to read them properly. I have a feeling this could just be an encoding problem or escaped characters.
Sample JS from my rendered HTML page:
<script type="text/javascript">/*<![CDATA[*/$('#videoUpload').uploadify({'script':'/manage/media/upload','uploader':'/assets/31bd69e5/uploadify.swf','expressInstall':'/assets/31bd69e5/expressInstall.swf','cancelImg':'/assets/31bd69e5/cancel.png','fileDataName':'videoUpload','buttonText':'Select a file','scriptData':{'videoUpload':' ','SESSION_ID':'a2ejd3hlc86mat05ld206vk9a3'},'folder':'/assets/31bd69e5','multi':true,'onOpen':'console.log(\"testing\")'});jQuery(function($) {jQuery('#yw0').yiiListView({'ajaxUpdate':['yw0'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'list-view-loading','sorterClass':'sorter'});});/*]]>*/</script>
So this should just make a console log when it runs, but…no dice!
I’d like to know why my actionUpload() action handler is not hit by the debugger ? The file is stored as expected so the actionUpload() code is definitely executed. But also why is my flash message not displayed ?
Here’s my code:
//view
$this->widget('application.extensions.uploadify.MUploadify', array(
'name' => 'myPicture',
'buttonText'=>'Upload your Diploma',
'script'=> array('client/upload'),
'fileExt'=>'*.jpg;*.png;',
'auto'=>true,
));
//controller
function actionUpload() {
if (isset($_POST['myPicture'])) {
$myPicture = CUploadedFile::getInstanceByName('myPicture');
if (!$myPicture->saveAs('someFile.ext')){
throw new CHttpException(500);
}
else{
Yii::app()->user->setFlash('success', "Data1 saved!");
}
echo 1;
Yii::app()->end();
}
}
?>
For for some reason, as soon as I add the property ‘onAllComplete’ the “black upload button” is replaced by the standard HTML file input, so it’s not possible to upload in one go. Even if I had the Upload link it does not work…
Which is the correct path! BUT I don’t think it is able to access my actionUpload function to process the request.
I have tried manually creating a text log file to see if the function is being called, but nothing is being created which leads me to believe that it is not being called.
Is there a way to track what params are being passed?
Here is my CfileLogRoute for a request:
2011/12/16 10:04:38 [error] [exception.CHttpException.400] exception ‘CHttpException’ with message ‘The CSRF token could not be verified.’ in /Users/brentyoung/Sites/yiiframework/framework/web/CHttpRequest.php:864
I Googled the CSRF error and found a fix something to do with ‘YII_CSRF_TOKEN’ => Yii::app()->request->csrfToken which must be passed as a parameter, but I am not sure how to go about it…