Xupload And Model

Hello. i want integrate XUpload to my yii application. But i have 2 problems:

  1. after upload image they correctly saved to tmp folder



//protected/controllers/SiteController.php (line 95)


//Move our file to our temporary dir

$model->file->saveAs( $path.$filename );

chmod( $path.$filename, 0777 );



But in model when tmp image must move to another folder and rename to real image name (exmaple: photo.jpg)




//protected/models/Images.php (line 108)


if (rename($image["path"], $path . $image["filename"])) {

    chmod($path . $image["filename"], 0777);

    $img = new Image();

    var_dump($img);

    $img->size = $image["size"];

    $img->mime = $image["mime"];

    $img->name = $image["name"];

    $img->source = "/images/uploads/{$this->id}/" . $image["filename"];

    $img->somemodel_id = $this->id;

    if (!$img->save()) {

        //Its always good to log something

        Yii::log("Could not save Image:\n" . CVarDumper::dumpAsString(

                        $img->getErrors()), CLogger::LEVEL_ERROR);

        //this exception will rollback the transaction

        throw new Exception('Could not save Image');

    }

}



its not happen. image moved. but not rename. This is part of code not execute, but why?

  1. At this app i have 1 filed - title and XUpload form. I want to save all uploaded image to database, but i dint now how its make and i have error in step

I follow to this manual http://www.yiiframework.com/wiki/348/xupload-workflow/. Help me please. I am the second day trying to make it.

P.S. I upload my app - http://yadi.sk/d/ioG6Tvyq1yVRA for greater clarity. Dump of db in data folder. And sorry for my english

[color="#006400"]/* moved from General Discussion */[/color]

clearly your code:


rename($image["path"], $path . $image["filename"])

Is returning false, that means It cant rename it for some reason, try to check that $image["path"] exists, and that $path . $image["filename"] is a valid path, and that is writable