Yii Framework Forum: ajaxSubmitButton Problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ajaxSubmitButton Problem Rate Topic: -----

#1 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 15 February 2010 - 05:54 AM

Hey guys,

I'm new to Yii and was playing around with the ajaxSubmitButton function in one of my forms. It seems to post the data no problems however it's not uploading any files. Same form works fine when not using ajax. Here is my code;

View
-----
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>

_form view
<?php echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

field for uploads
<?php echo CHtml::activeFileField($model,'photos_file',array('size'=>45,'maxlength'=>45)); ?>

Controller
public function actionCreate()
	{
		$model=new Photos;
		if(isset($_POST['Photos']))
		{
			$model->attributes=$_POST['Photos'];
            $model->photos_file=CUploadedFile::getInstance($model,'photos_file');
			if($model->save())
            {
                $this->uploadImage($model);
                //redirect
				$this->redirect(array('view','id'=>$model->photos_id));
		    }
        }

		$this->render('create',array(
			'model'=>$model,
		));
    }

//Upload image function
    public function uploadImage($photo)
    {
        //Check if photos dir exists
        if(!is_dir(Yii::app()->params['fileStorage'].'/photos'))
        {
            mkdir(Yii::app()->params['fileStorage'].'/photos');
        }
        //Check if directory exists
        $dir_to_save=Yii::app()->params['fileStorage'].'photos/'.$photo->photos_id;
        if(!is_dir( $dir_to_save))
             {
             mkdir( $dir_to_save);
             }
        $photo->photos_file->saveAs($dir_to_save.'/'.$photo->photos_file->name);
         //create thumbnail
         $image=Yii::app()->image->load($dir_to_save.'/'.$photo->photos_file->name);
         $image->resize(50,50);
         $image->save($dir_to_save.'/thumb_'.$photo->photos_file->name);
    }


Any ideas why i can't upload this file using ajax?

Cheers,
Snorcha
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 15 February 2010 - 11:24 AM

I don't think you can upload an image the ajax way... :-[
0

#3 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 15 February 2010 - 04:07 PM

View Postbettor, on 15 February 2010 - 11:24 AM, said:

I don't think you can upload an image the ajax way... :-[


Oh bumma! - I was hoping you could.

Thanks for the reply.
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 16 February 2010 - 03:03 AM

View Postsn0rcha, on 15 February 2010 - 04:07 PM, said:

Oh bumma! - I was hoping you could.

Thanks for the reply.


Check google...there are lots of ways to fake ajax image upload tho.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users