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);
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
$image_file=CUploadedFile::getInstance($model, 'imagefile');
if(!is_object($image_file))
{
$this->redirect(array('update', 'id'=>$model->id));
}
if($model->save())
$internalPath=$model->internal_path;
$image_file->saveAs(Yii::app()->baseUrl.$internalPath);
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
In the form:
<div class="row">
<?php echo CHtml::activeFileField($model, 'imagefile'); ?>
<?php echo $form->error($model,'imagefile'); ?>
</div>
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.
Alex