CUploaded File

Hi all,

I’m facing a problem with CUploadedFile. When I upload a new file, it work normaly. After uploaded, I open the file which I upload before. And then I try to upload again (in the second case, the upload file which name is the same with the old file, but the old file is opening by editor), and I got a error warning like :

How can I fix this? Any idea, plaase :blink:

Regard,

I love unique name of uploaded files. And I hope you like this snippet:




    public function actionCreate() {

        $model = new Immagini;

        if (isset($_POST['Immagini'])) {

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

            if ($model->save()) {

                $nomeImmagine = @$_FILES["Immagini"]["name"]["immagine"];

                $nomeUnivoco = (md5($nomeImmagine . mktime() . $model->id)) . '.' . (end(explode('.', $nomeImmagine)));

                $originale = Yii::app()->basePath . "/../uploads/" . $nomeUnivoco;

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

                $model->immagine->saveAs($originale);

                $model->immagine = $nomeUnivoco;

                $model->save();

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

            }

        }

        $this->render('create', array(

            'model' => $model,

        ));

    }