Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Zii » Jui » How to upload image in a CJuiDialog (modal)
0 Votes
Vote Con!
Solved!

How to upload image in a CJuiDialog (modal)

CJuiDialogimage upload

Hello all,

I’m trying (w/ no success) to upload an image in a CJuiDialog.

I have (sucessfully) used before the image upload field, but can not get it to work w/ Ajax.

Here is the (working) code I used before
view

  1. beginWidget('CActiveForm', array(
  2.     'id'=>'personasform',
  3.     'enableAjaxValidation'=>true,
  4.         'htmlOptions'=>array('enctype'=>'multipart/form-data'),
  5. )); ?>
  6. ...
  7. echo $form->fileField($model,'rutaImagen',array());
  8. ...
beginWidget('CActiveForm', array(
	'id'=>'personasform',
	'enableAjaxValidation'=>true,
        'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
...
echo $form->fileField($model,'rutaImagen',array());
...

Controller

  1. ...
  2. $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
  3. ...
  4. $model->rutaImagen->saveAs($fullPath);
...
$model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
...
$model->rutaImagen->saveAs($fullPath);

Here is new code which does not work.

view

  1. $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
  2.     'id'=>'mydialog2',
  3.     // additional javascript options for the dialog plugin
  4.     'options'=>array(
  5.         'title'=>'Dialog box 1',
  6.         'autoOpen'=>false,
  7.        
  8.         'modal'=>true,
  9.         'width'=>550,
  10.         'height'=>500,
  11.        
  12.     ),
  13. )); ?>
  14. ...
  15. beginWidget('CActiveForm', array(
  16.     'id'=>'amigo-form',
  17.     'enableAjaxValidation'=>true,
  18.     'htmlOptions'=>array('enctype'=>'multipart/form-data'),
  19. )); ?>
  20. ...
  21. echo $form->fileField($model,'rutaImagen',array());
  22. ....
  23.         echo CHtml::ajaxSubmitButton('Create Job',CHtml::normalizeUrl(array('people/addnew2','render'=>false)),
  24.             array('success'=>'js: function(data) {
  25.                             $("#mydialog2 div.divForForm2").html(data);
  26.                
  27.                
  28.                 }'),array('id'=>'closeJobDialog'));
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'mydialog2',
    // additional javascript options for the dialog plugin
    'options'=>array(
        'title'=>'Dialog box 1',
        'autoOpen'=>false,
        
        'modal'=>true,
        'width'=>550,
        'height'=>500,
        
    ),
)); ?>
...
beginWidget('CActiveForm', array(
	'id'=>'amigo-form',
	'enableAjaxValidation'=>true,
	'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
...
echo $form->fileField($model,'rutaImagen',array());
....
		echo CHtml::ajaxSubmitButton('Create Job',CHtml::normalizeUrl(array('people/addnew2','render'=>false)),
			array('success'=>'js: function(data) {
                    		$("#mydialog2 div.divForForm2").html(data);
				
				
			    }'),array('id'=>'closeJobDialog')); 

in controller

  1. ...
  2. $model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
  3. // which does NOT bring anything if echoed
  4. ...
  5. $fullPath = "c:/archivo.jpg" ;
  6. ...
  7. $model->imagen->saveAs($fullPath);
  8. // get an error trying to save nothing
  9. //  500  - Internal Server Error
  10. // paths are correct
...
$model->rutaImagen=CUploadedFile::getInstance($model,'rutaImagen');
// which does NOT bring anything if echoed
...
$fullPath = "c:/archivo.jpg" ;
...
$model->imagen->saveAs($fullPath);
// get an error trying to save nothing
//  500  - Internal Server Error
// paths are correct

I have tried a bunch of things including:
– using extensions
– use CHtml::ajaxSubmitButton

Questions:
– How to submit images using ajax?
– How to debug the things that are sent in Ajax. In browser I only see the rest of the fields (textfields w/ values) except file.

Thanks

By tuolden in Jui · Asked 585 days 20 hours 40 mins ago

Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0

 

Answers (1)

  1. 0 votes
    Accepted

    Hack … But it works

    I’m using eajaxupload

    I just upload file first & then using a hidden field move it to the right folder w/ form is submitted.

    Any other suggestions are more than welcome.

    By tuolden · 585 days 19 hours 8 mins ago

    Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site