开发者

File not uploading to dynamic directory in Yii

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜