Yii Framework Forum: Saving Images In Another Webapp - Yii Framework Forum

Jump to content

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

Saving Images In Another Webapp Using two separate yii-installs Rate Topic: -----

#1 User is offline   Solid 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 29-December 12
  • Location:Kristiansand, Norway

Posted 11 February 2013 - 01:51 PM

Hi all!
Prolly a fast one for the experienced users.
I have a webapp for my public_html and one for my admin_html, server-root like this:

SERVER
-framework/
-protected/
-admin_prot/
-public_html/
-admin_html/

Separating the backend totally from the frontend.

My problem is when im uploading images in my backend, i cant seem to save them in my frontend.. iv'e tried several variations like:
$model->pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$model->pic);
$model->pic->saveAs(Yii::getPathOfAlias('webroot').'/../images/'.$model->pic);

ive allso tried Yii::setPathOfAlias('public_images', '/public_html/images/');

Anyone care to tell me where i stepped wrong? :)

Appriciate it!
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 11 February 2013 - 03:00 PM

Dear Friend

$model->pic->saveAs($model->pic);


The above code would save the image in webroot folder itself.

$model->pic->saveAs("images/".$model->pic);


The above code will save the image in webroot/images folder.

Regards.
0

#3 User is offline   Solid 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 29-December 12
  • Location:Kristiansand, Norway

Posted 13 February 2013 - 04:22 AM

Thank you,
that is an improvement on the code. But i cant seem to work out how thats helpfull to my actual problem :)
Anyone have any sulution on saving an image in folders behind the webroot and application?
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 13 February 2013 - 09:32 AM

Dear Friend

Kindly check that whether the following is helpful to you.

I hope there may be better and simpler solution exists.

Now I have two applications(yii) in my localhost.

1.boost.(/var/www/boost)

2.nivas.(/var/www/nivas)

Now we want to save images from application boost into a folder residing in application nivas.

That means we want to save in /var/www/nivas/images.

The following is the controller logic in boost.

public function actionUpload()
{
	$model=new FileForm;
	$webPath=dirname(dirname(Yii::app()->basePath));
	$imagePath=$webPath."/nivas/images";
	if(isset($_FILES["FileForm"]))
	{
		$files=CUploadedFile::getInstances($model,"files");
		foreach($files as $file)
			$file->saveAs($imagePath."/".$file->name);
						
	}

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


Yii::app()->basePath;//   /var/www/boost/protected


dirname(Yii::app()->basePath);//    /var/www/boost 


dirname(dirname(Yii::app()->basePath));//  /var/www


dirname(dirname(Yii::app()->basePath))."/nivas/images";//   /var/www/nivas/images 


I hope I helped a bit.

Regards.
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