SWFUpload Issues an Usage Discussion

Just relesed the SwfUpload extension.

I would like to try this extension but I keep getting error 500

Some questions…

Did you enabled Yii CSRF?

Could you post your code for me? (Controller, Model and View)

Sure man! thanks for reverting to the problem. Please note, I am not using the model.

View:

note: ‘upload_success_handler’=>‘js:uploadSuccessListView’ gives error

uploadSuccessListView is not defined http://localhost/gfied/garage/seller/upload_images Line 75

I changed that line to : ‘upload_success_handler’=>‘js:uploadSuccess’




<?php

$handlers_js = URL_BASE.'js/handlers.js';

Yii::app()->clientScript->registerScriptFile($handlers_js,CClientScript::POS_HEAD);

?>


<?php

$this->widget('application.extensions.swfupload.CSwfUpload', array(

        'postParams'=>array(),

        'config'=>array(

                'use_query_string'=>true,

                'upload_url'=>$this->createUrl('/garage/seller/actionupload'), 

                'file_size_limit'=>'2 MB',

                'file_types'=>'*.jpg;*.png;*.gif',

                'file_types_description'=>'Image Files',

                'file_upload_limit'=>0,

                'file_queue_error_handler'=>'js:fileQueueError',

                'file_dialog_complete_handler'=>'js:fileDialogComplete',

                'upload_progress_handler'=>'js:uploadProgress',

                'upload_error_handler'=>'js:uploadError',

                'upload_success_handler'=>'js:uploadSuccess',

                //'upload_success_handler'=>'js:uploadSuccessListView',

                'upload_complete_handler'=>'js:uploadComplete',

                'custom_settings'=>array('upload_target'=>'divFileProgressContainer'),

                'button_placeholder_id'=>'swfupload',

                'button_width'=>170,

                'button_height'=>20,

                'button_text'=>'<span class="button">'.Yii::t('messageFile', 'ButtonLabel').' (Max 2 MB)</span>',

                'button_text_style'=>'.button { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 11pt; text-align: center; }',

                'button_text_top_padding'=>0,

                'button_text_left_padding'=>0,

                'button_window_mode'=>'js:SWFUpload.WINDOW_MODE.TRANSPARENT',

                'button_cursor'=>'js:SWFUpload.CURSOR.HAND',

        ),

        )

);

?>

<?php echo CHtml::beginForm(); ?>

<div class="form">

    <div class="row">

        <div id="divFileProgressContainer"></div>

        <div class="swfupload"><span id="swfupload"></span></div>

    </div>

</div>

<?php echo CHtml::endForm(); ?>



My Controller looks like this:




    protected function actionUpload() {

        $filedata=$_FILES['Filedata'];

        @move_uploaded_file($filedata['tmp_name'],'C:/www/home/gfied/test.jpg'); // Not relative. Full path

    }


    public function actionUpload_images() {

        $this->render('upload_images');

    }



No error now, I have set enableCsrfValidation=true.

** But Image is not saving in the designated folder. **

Thanks

Sorry dude. The follow script i wrote to update one Yii CListView after download. You are right, use the uploadSuccess for regular purposes.




function uploadSuccessListView(file, serverData) {

	try {

		var progress = new FileProgress(file,  this.customSettings.upload_target);


		if (serverData.substring(0, 2) === "OK") {

			$.fn.yiiListView.update('listview');

		} else {

			progress.setStatus("Error.");

			progress.toggleCancel(false);

			alert(serverData);

		}




	} catch (ex) {

		this.debug(ex);

	}

}



About the file i tested here and it works fine. Strange… Keep trying… I lost one day fixing my code, now I know use it properly.

I get a 302 error

My controller:


    public function actionUploadLoga()

    {

    	$fd = fopen("upload/t.txt",'w');

    	fwrite($fd,'zegar');

    	fclose($fd); 

    	$filedata=$_FILES['Filedata'];

		move_uploaded_file($filedata['tmp_name'],'/var/www/zegarmistrz/elipse/gg2/upload/1.jpg');

    }

Unfortunately both files (t.txt and 1.jpg) are not created.

My view:




<?php $form = $this->beginWidget('CActiveForm',array(

	'id'=>'wizytowka',

	'enableAjaxValidation'=>false)); ?>

<?

$this->widget('application.extensions.swfupload.CSwfUpload', array(

    'jsHandlerUrl'=>'javascript/handlers.js', //Relative path

    'postParams'=>array(),

    'config'=>array(

        'use_query_string'=>true,

        'upload_url'=>CHtml::normalizeURL(array('uzytkownicy/uploadLoga')), //Use $this->createUrl method or define yourself

        'file_size_limit'=>'2 MB',

        'file_types'=>'*.jpg;*.png;*.gif',

        'file_types_description'=>'Image Files',

        'file_upload_limit'=>0,

        'file_queue_error_handler'=>'js:fileQueueError',

        'file_dialog_complete_handler'=>'js:fileDialogComplete',

        'upload_progress_handler'=>'js:uploadProgress',

        'upload_error_handler'=>'js:uploadError',

        'upload_success_handler'=>'js:uploadSuccess',

        'upload_complete_handler'=>'js:uploadComplete',

        'custom_settings'=>array('upload_target'=>'divFileProgressContainer'),

        'button_placeholder_id'=>'swfupload',

        'button_width'=>170,

        'button_height'=>20,

        'button_text'=>'<span class="button">Dodaj zdjęcie (Max 2 MB)</span>',

        'button_text_style'=>'.button { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 11pt; text-align: center; }',

        'button_text_top_padding'=>0,

        'button_text_left_padding'=>0,

        'button_window_mode'=>'js:SWFUpload.WINDOW_MODE.TRANSPARENT',

        'button_cursor'=>'js:SWFUpload.CURSOR.HAND',

        ),

    )

);

?>

<div class="form">

    <div class="row">

    <div id="divFileProgressContainer"></div>

    <div class="swfupload"><span id="swfupload"></span></div>

    </div>

</div>  

<?php $this->endWidget('CActioveForm');?>



Just make sure that you remove accessControl to your upload function action!!

In my case was:





public function filters()

	{

		return array(

			'accessControl -upload', // perform access control but for uploadAction

		);

	}




Hope this helps you!

Thanks for your help. Now it is working fine.

Not a problem! I am glad it worked for you too… The developer should include this info into the Extension details.

Best

First thank you for the great widget.

I did run into problem when using this - I can’t upload any file larger then 100M even if I set all to following variables to 150M:

swfupload: file_size_limit

HTML form hidden MAX_FILE_SIZE

PHP memory_limit, upload_max_filesize and upload_max_size

Am I missing anything?

Thanks

Thanks dude! I think you should talk to your server to check the size limit of uploads. But I will check it anyway!

Yeah I will do this. Thanks for advice!

Actually I had this problem and disabled Yii Csrf to extension work now I know how to solve it. Thanks guys!

Thank you for the quick response. The code is currently running on my dev machine’s xampp therefore I don’t have a upload limit. On top of it, a regular PHP post upload of 150M+ file seems to be fine. I even play with apache’s LimitRequestBody directive with no success.

Thanks in advance.

ops… now I don’t know. Can you try at swfuplod support forum? Maybe its a plugin issue. I’m still trying to solve it.

Follow link http://www.swfupload.org/

I see the same problems here that occurs with swfupload plugin when programming in javascript. It could be good that we include the possible problems and solutions within A PROBLEMS_SOLUTIONS.TXT file in the packaged document.

We have already found a couple here and if we do it this way, we could just improve the plugin making it better for everybody to understand and install and solve any possible problems.

Most common are:

Error 302 <— redirection -solved here

Error 404 <— url not found -this is easy right?

Error 500 <— solved here

Error

Error

well, just google it out there and there a huge list. What do you think about it thiagovidal? By the way, thanks to save my time!

Great extension

unable to login with PHPSESSID. how to solve that?

Hello people!

I’ve detected an error in postParams:

If I set:




$postParams = array(

            'one'=>'1',

            'two'=>'2',

            'three'=>'3'

            );



Next, in controller:




            Yii::trace('ONE:'.$_POST['one'],'dblog');

            Yii::trace('TWO:'.$_POST['two'],'dblog');

            Yii::trace('THREE:'.$_POST['three'],'dblog');



I obtain:

ONE: 1&two=2&three=3

TWO: (empty)

THREE: (empty)

So…, it appears that all $postParams are joined in the first element.

Is that a Bug?

It seems that SwfUpload had a problem on that matter before: http://code.google.com/p/swfupload/issues/detail?id=69

Yes but that issue appears is closed and not solved.

I would like to use SWFupload in the form, just like formsdemo. After submit button is clicked, the file selected starts uploading. But the file uploading could not be completed.

I modified the handlers.js according to the example, formsdemo. But ‘swfu’ could not be found!




function doSubmit(e) {

	if (formChecker != null) {

		clearInterval(formChecker);

		formChecker = null;

	}

	

	e = e || window.event;

	if (e.stopPropagation) {

		e.stopPropagation();

	}

	e.cancelBubble = true;

	

	try {

		swfu.startUpload();

	} catch (ex) {


	}

	return false;

}



When I didn’t use the submit button. The file was uploaded after selection at once. It works well!




function fileDialogComplete(numFilesSelected, numFilesQueued) {

    this.startUpload();

}