MUploadify

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");}',



The author of uploadify released version 3.1 of the plugin, just a question whether the author of the extension plans to update it.

thank you.

Hi Qusnips/Satori,

Are you able to get it working with Uploadify 3.1 version ? Mine is Broken and I am debugging it . The browse button is coming up , but clicking on browse nothing is happening .

Please let us know if you have the solution .

Thanks for your help

Regards

Yii Fan

In MUploadify.php changing uploader to ‘swf’ helped

Now it should be ‘swf’=>$this->getBaseUrl().’/uploadify.swf’,

May be there are other changes to I am checking them

Hi Gustavo,

I have a scenario where I want the user to upload any number of diplomas they want. So I am using some ajax with a "Add diploma" button that generates a new entry with a MUpoadify widget.

So in a nutshell I have a _diploma.php file and the action triggered by the “Add Diploma” button uses renderPartial( ‘_diploma’ ).

The problem is that it does not render properly the button ! It seems to be an AJAX issue as when I use the renderPartial( ‘_diploma’ ) normally it works. You can see in the screenshort the first row is rendered when the page is loaded while the second is rendered after the user clicks “Add Diploma”. In both cases the same code is executed (the renderPartial).

2836

Capture.JPG

Any idea ?

Cheers

Renaud

Im trying to pass some textbox values to scriptData using the approach below. my implementation of MUplodify works fine, but the problem is that the data I want to pass doesn’t get passed to the “scriptData”

In my view file(_form.php) getSomeData() is a javascript function which I have included and registered in the controller file of my model. it even gets loaded…ive checked its availability, it returns the value i want if i fire it from firebug console.

I believe im not using the proper way to pass dynamic values from any form to the "scriptData".

Should i try something like ‘onSelect’ and use .uploadifySettings(‘scriptData’:…if so how do i use it using the widget?

any kind of guidance or help Id appreciate.

Thanks




//view

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

                        

                        'model'=>$model,

                        'attribute'=>'data',

                        'scriptData'=>array('SomeData'=> 'getSomeData()'),

 

                        ));



did you solve the problem? i am also having the same problem. HTTP error . action assigned to script in the widget paramater does not get called. but the action with scriptCheck does get called.