Cuploadedfile And Saveas Issue

I am having trouble saving the file to the correct folder (Windows). The folder that I need to save to is:

C:\apache\htdocs\mysite\images\user\

So I have tried to do the following:


uploaded_file = CUploadedFile::getInstance($user, 'cover_photo');


if($uploaded_file)

{

	$save_path = Yii::app()->basePath . '/images/user/';

	

	$user->cover_photo = $uploaded_file;

	

	$uploaded_file->saveAs($save_path . $user->cover_photo);

	

	$user->update();

}

But this does not work - it says move_uploaded_file - “No such file or directory”. It seems like basePath is the ‘protected’ folder, but this is not where my images folder is. Can anyone advise how to do this correctly? Bear in mind when the application is complete it will be hosted on a Linux server, so the solution needs to be multi-platform compatible.

Hi

you can use this some thing look like this


$path	= YiiBase::getPathOfAlias('webroot');

 		  $url ='http://'.$_SERVER['HTTP_HOST']. Yii::app()->baseUrl;

		  $model->image=$_FILES['Coupon']['name']['image'];

		  $model->image = CUploadedFile::getInstance($model, 'image');

		  $model->image->saveAs($path.'/upload/coupon/'.$model->image);

Is there no proper "yii" way of doing it?

Like a function that returns the application path without "protected"?

Try Yii::app()->basePath.’/../yourfolderhere’.

Hi GSTAR!

you are directly assigning the instance of cuploadedfile like this




$user -> cover_photo = $uploaded_file ;



so it doesn’t work try this




$user -> cover_photo = $uploaded_file->name;

//and save

$uploaded_file -> saveAs ($save_path . $user -> cover_photo );

//this will work