MUploadify

Thanks Gustavo!

I solved it that way:




        $decodeData = json_decode($_POST['galleriaPicture']);

        $queryString_id_url = $decodeData->pageView_id;        

        $galleriaPicture=CUploadedFile::getInstanceByName('galleriaPicture');

        $uploadedPicture = $galleriaPicture->getName('galleriaPicture');

        $galleriaPicture_url = 'images/gallery/'.$queryString_id_url.'/'.$uploadedPicture; 

Hi All -

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!

Anyone see behavior like this before?

Thanks,

Matt

Nevermind, I just noticed I was missing "JS:" in front of the javascript on the override!

Cheers -

Matt

Hi there,

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();

        }

    }

    ?>

Any idea ?

Renaud

HI Renaud

It is because the request is sent by a flash application (uploadify.swf), therefore it does not save cookies, and flash messages are stored as cookies

If possible, use the onAllComplete to display a message for the user, or store the message someway else




'onAllComplete'=>'js:function(){

  $("#myMessageField").html("Data saved! ");

}'



Hi Gustavo,

Thanks for your quick reply.

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…

My code is this :




        $this->widget('application.extensions.uploadify.MUploadify', array(            

            'name' => 'myPicture',

            'buttonText'=>'Upload your Diploma',

            'script'=> array('client/upload'),

            'fileExt'=>'*.jpg;*.png;',            

            'auto'=>true,

            'onAllComplete' => 'js:function(){$("#myMessageField").html("Data saved! ");',

        ));



Am I missing something ?

Cheers

Renaud

I can’t see anything wrong.

It is most probably not working because of some error in the js code generated.

Check the console tab of your firebug for any js error.

Yes I was indeed missing a ‘}’. I don’t like Javascript…

Hi,

I am getting a HTTP 400 error and for the life of me, I cannot figure out why?

The following code I am placing in my controllers/AdminController within my Company Module:




	function init(){

		if(isset($_POST['SESSION_ID'])) {

			$session=Yii::app()->getSession();

			$session->close();

			$session->sessionID = $_POST['SESSION_ID'];

			$session->open();

		}

	}


	function actionUpload() {

		$model=new Company;

		if(isset($_POST['Company'])){

			$model->logo=CUploadedFile::getInstance($model,'logo');

			if(!$model->save()) throw new CHttpException(500);

			$model->logo->saveAs('someFile.jpg');

			Yii::app()->end();

		}

		echo 1;

	}




Then I am using the following code within my _form.php page to create and update my company information:




$this->widget('MUploadify',array(

		  'model'=>$model,

		  'attribute'=>'logo',

		  'script'=>$this->createUrl('/company/admin/upload'),

		  'auto'=>true,

		  'onError' => 'js:function(evt,queueId,fileObj,errorObj){alert("Error: " + errorObj.type + "\nInfo: " + errorObj.info);}',

		));



The callback onError gives me the type: HTTP Error, info: 400.

The "progress bar" also returns the message HTTP Error.

I have checked the log to make sure that it is using the correct path to my actionUpload method and it seems fine.

#4 {main} REQUEST_URI=/example.com/company/admin/upload

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.

Any ideas?

I can’t see anything wrong with your code

http code 400 means "bad request", you might not be passing the correct parameters somewhere (the code posted seens right tho)

Use file log ( CFileLogRoute ) and check the log, and if you don’t see the problem post the log here

Thanks for the speedy reply…

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

Stack trace:

#0 /Users/me/Sites/yiiframework/framework/base/CComponent.php(571): CHttpRequest->validateCsrfToken(Object(CEvent))

#1 /Users/me/Sites/yiiframework/framework/base/CApplication.php(185): CComponent->raiseEvent(‘onBeginRequest’, Object(CEvent))

#2 /Users/me/Sites/yiiframework/framework/base/CApplication.php(157): CApplication->onBeginRequest(Object(CEvent))

#3 /Users/me/Sites/example.com/index.php(13): CApplication->run()

#4 {main} REQUEST_URI=/example.com/company/admin/upload

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…

Any further thoughts on the above?

Sorry, I have never used CSRF token, so I can’t help you further.

Maybe someone with more experience on it will

Maybe you should start using it?

Because it needs to be fixed in the extension.

I’ll see if I can find the time to grab an example, but IIRC: one of the other upload extensions has support for csrf.

Here is something:


$_csrf = Yii::app()->request->csrfToken;

In some javascript/HTML/view:





<form id='uploadfrm' enctype='multipart/form-data' action='/site/upload' method='post'>

<fieldset>

<div style='display: none;'><input value='{$_csrf}' name='YII_CSRF_TOKEN' type='hidden'></div>

...



This extension does not work with Yii 1.1.8, presumably because of the jQuery version.

No javascript errors just a hard fail of all things jQuery.

Thanks for the info

I`ll check on it asap

Edit. I got to fix the problem here.

But, now i have a new doubt.

The extension don’t limit the size of queue?

By example, if i put 6 in the "queueSizeLimit", it allows me to select a maximum of 6 files. But, i can select 6 files several times.

I can select 6, then open de upload window e select 6 more, so on.

There’s a way to prevent this?

Hi,

I need to have ,multiple uploadify on my page. So added the following code:


<?


$this->widget('application.extensions.muploadify.MUploadify',array(


  'name'=>'uploadme'.$i,

   'uploader' => '/protected/js/uploadify.swf', 

            'script' =>array('Releases/Upload','id'=>$_GET['id'],'ivalue'=>$i), 

			

            'cancelImg' => '/protected/js/cancel.png',

            'auto' => true,

            'multi' => false,

           'folder' => '/web/releases', 

			'queueSizeLimit'=>1,

			'scriptData' => array('extraVar' => 1234, 'PHPSESSID' => session_id()),

		

			'fileExt' => '*.mp3',

			'fileDesc'    => 'Music Files (.mp3)',

			'queueSizeLimit'=>1, 

			'queueId'=>'thequeue'.$i,

		   'sizeLimit'=>512000, 

		

			'onError' => 'function(evt,queueId,fileObj,errorObj){

			if (errorObj.type ==="File Size")

			alert(fileObj.name+" "+errorObj.type+" Limit:500KB");

			else

			alert("Error: " + errorObj.type + "\nInfo: " + errorObj.info);

			}',

			

			'onComplete' =>' function(event, ID, fileObj, response, data){alert( fileObj.name);

			$(\'#track'.$i.'\').val($(\'#track'.$i.'\').val() + fileObj.name);

			}',

			

			'onCancel' => 'function(evt,queueId,fileObj,data){alert("Cancelled");}',

        

));

?>

But none of the events r working.I need to alert a message if the file size is more than 500kb n i am not able to cancel an upload …

Please suggest something…

Thanks

Mithila

prefix the events with js:, like


'onCancel' => 'js:function(evt,queueId,fileObj,data){alert("Cancelled");}',