File upload help please

I’m having problems getting a file uploaded using any method. Currently I am trying to upload files using a model and storing them in an OS directory.

Starting at the end, I get this error message.

move_uploaded_file(/hawkwebapp/assets/hawk/images/31-photo.jpg) [<a href=‘function.move-uploaded-file’>function.move-uploaded-file</a>]: failed to open stream: No such file or directory

Please notice that the move_uploaded_file only has one parameter. Even though CUploadedFile.php is using this line of code which contains 2 parameters:

return move_uploaded_file($this->_tempName,$file);

I think part of the message "No such file or directory" refers to the empty parameter? The location of the temp file? If I manually place the correctly named file in the destination directory, it displays just fine.

I have read “How to upload a file using a model” and to the best of my knowledge I have everything entered as suggested. Here’s how I have it set up:

In the model:

public $imagefile;

public function rules()


            return array(

              //more rules

              array('imagefile', 'file', 'types'=>'jpg, gif, png'),

              //more rules



In the controller:

public function actionCreate()


		$model=new Image;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);




			$image_file=CUploadedFile::getInstance($model, 'imagefile');



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












In the form:

<div class="row">


        <?php echo CHtml::activeFileField($model, 'imagefile'); ?>

        <?php echo $form->error($model,'imagefile'); ?>



My development environment is running in MAMP on my local Mac. All relevant directories have read/write access for everyone.

I hope someone can help. This should be such a simple thing to accomplish. I’ve tried it with the model upload like here. I’ve tried a database blob approach. I’ve looked at the upload extension. I can’t get anything to work. I’ve been working on this so long my mind is mush.

All help is appreciated.


I forgot to say that I did add the multipart designation to the form:

<?php $form=$this->beginWidget('CActiveForm', array(






)); ?>

Hi Alex,

"failed to open stream: No such file or directory" meens the path returned by Yii::app()->baseUrl.$internalPath not found

or have not the right to access to it, please can you check Yii::app()->baseUrl.$internalPath.

Good luck.

Hi alex,

i think the saveAs path was wrong, you try to create a folder inside protected, example images. Then change this code

change from

$image_file=CUploadedFile::getInstance($model, 'imagefile');

to below code


change from


to below code ( assume your path is inside protected/images/


below this link might help you:

let me know if this amend was working :)

Hi, Alex

Today, i have a problem like yours, i found the solution i tried by use the file system path in saveAs method. I think move_upload_file interface in file system level , so i use this statement

$model->image->saveAs(Yii::app()->basePath./images/… )

it will store ur image file in /protected/images/ folder

Thank u