$Model->Image->Saveas('path/to/localfile'); Not Working

I followed the step by step instruction given by this link My link.

It worked out just fine, but it only save file into database and not in the ‘directory’ I included.

This is my controller:





		if(isset($_POST['PurchaseRequest']))

		{

			

	

			$model->attributes=$_POST['PurchaseRequest'];

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

			$model->class_name = $options->getCategoryatIndex($model->class_name);

			if($model->save()){

				$model->purchase_document->saveAs('.\files\pr');

				$this->redirect(array('view','id'=>$model->id));

				

			}

		}



Note that i changed the (‘files/pr’) to (’.\files\pr’) for it to work because i get an error if I used the first one. I would really appreciate if someone can help me with this. Thank you.

Did you change the access permissions (chmod 777) to the folder created?

Yes. and still it does’nt work. :’(

I think the problem is with the path, try with [dirname(FILE).’/../path/to/file’]

Can you share the path of your folder created?

this is the path of the folder I created /var/www/MyWebApp/files

If so, then the path should be something like ‘/files’

Try with the following:




$model->purchase_document->setPath('/files');

$model->purchase_document->saveAs();



but it says ‘CUploadedFile and its behaviors do not have a method or closure named “setPath”.’

you are just instructing to save on your path like this


$model -> purchase_document -> saveAs( '.\files\pr' );

append file name like this


$model -> purchase_document -> saveAs( '.\files\pr\foo.bar');




$model->purchase_document->saveAs('/files');



It works, but still only saves the file to database and not on the directory I set.

I tried that code several times, but still don’t work for me :(

My code works now. I found this link useful My link.

Anyway, thank you guys! :D

Great

;D

Thanks to refer my Wiki.

Don’t forgot to give plus (+ve) point :D