For a file upload I have the action below. This creates a dir with the currentDate as I have defined in my model and a uploads my file renaming it to the ImageId.
The problem is that the directory and Image are both created within the same dir. I need the Image to be placed in the newly created directory though. Any ideas?
$model->attributes=$_POST['ImageUpload'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
{
exec("mkdir -p " . Yii::app()->basePath . "/../images/uploads/$data->currentDate开发者_Go百科");
$model->image->saveAs(Yii::app()->getBasePath()."/../images/uploads/$data->currentDate/$model->ImageId");
$this->redirect(array('view', 'id' => $model->ImageId));
}
Are you sure you have anything in $model->ImageId?
I'm using roughly the same code:
if (!file_exists ($fileSavePath))
mkdir ($fileSavePath, 0, true);
$fileSavePath .= $form->my_file->name;
$form->my_file->saveAs ($fileSavePath);
精彩评论