ARContract::addImages PHP Method

addImages() public method

public addImages ( )
    public function addImages()
    {
        //If we have pending images
        if (Yii::app()->user->hasState('images')) {
            $userImages = Yii::app()->user->getState('images');
            //            dump($userImages);exit;
            //Resolve the final path for our images
            //	    $path = Yii::app()->getBasePath() . "/../images/uploads/";
            //	    $path = realpath(Yii::app()->getBasePath() . "/../upload/item/image") . "/";
            //	    //Create the folder and give permissions if it doesnt exists
            //	    if (!is_dir($path)) {
            //		mkdir($path);
            //		chmod($path, 0777);
            //	    }
            //Now lets create the corresponding models and move the files
            foreach ($userImages as $k => $image) {
                if (is_file($image["path"])) {
                    //		    if (rename($image["path"], $path . $image["url"])) {
                    //			chmod($path . $image["filename"], 0777);
                    //		    $img = new ItemImg( );
                    $img = new ARGrouponAttach();
                    $img->relation_id = $this->id;
                    $img->title = $this->name . 'ๅˆๅŒ้™„ไปถ';
                    $img->file_path = $image['filename'];
                    $img->create_time = time();
                    //			$img->size = $image["size"];
                    //			$img->mime = $image["mime"];
                    //			$img->name = $image["name"];
                    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');
                    }
                    //		    }
                } else {
                    //You can also throw an execption here to rollback the transaction
                    Yii::log($image["path"] . " is not a file", CLogger::LEVEL_WARNING);
                }
            }
            //Clear the user's session
            Yii::app()->user->setState('images', null);
        }
    }