<?php
/**
* @property string $id
* @property string $name
*/
class Image extends CActiveRecord {
public $image;
public function rules(){
array('image', 'file', 'types'=>'jpg, gif, png'), );
}
}
class ImageController extends Controller {
public function actionIndex(){
$this->render('index');
}
public function actionCreate(){
$model=new Image;
if(isset($_POST['Image'])){ $model->attributes = $_POST['Image'];
$model->image = CUploadedFile::getInstance($model, 'image');
if($model->save()){
$model->image->saveAs('images');
$this->refresh();
}
}
$this->render('create', array('model'=>$model)); }
}
PD9waHAKCi8qKgogKiBAcHJvcGVydHkgc3RyaW5nICRpZAogKiBAcHJvcGVydHkgc3RyaW5nICRuYW1lCiAqLwpjbGFzcyBJbWFnZSBleHRlbmRzIENBY3RpdmVSZWNvcmQgewoJcHVibGljICRpbWFnZTsKCXB1YmxpYyBmdW5jdGlvbiBydWxlcygpewoJCXJldHVybiBhcnJheSgKICAgICAgCQlhcnJheSgnaW1hZ2UnLCAnZmlsZScsICd0eXBlcyc9PidqcGcsIGdpZiwgcG5nJyksCgkJKTsKCX0KfQpjbGFzcyBJbWFnZUNvbnRyb2xsZXIgZXh0ZW5kcyBDb250cm9sbGVyIHsKCXB1YmxpYyBmdW5jdGlvbiBhY3Rpb25JbmRleCgpewogICAgCSR0aGlzLT5yZW5kZXIoJ2luZGV4Jyk7Cgl9CiAgCXB1YmxpYyBmdW5jdGlvbiBhY3Rpb25DcmVhdGUoKXsKCSAgICAkbW9kZWw9bmV3IEltYWdlOwoJICAgIGlmKGlzc2V0KCRfUE9TVFsnSW1hZ2UnXSkpewoJICAgIAkkbW9kZWwtPmF0dHJpYnV0ZXMgPSAkX1BPU1RbJ0ltYWdlJ107CgkgICAgCSRtb2RlbC0+aW1hZ2UgPSBDVXBsb2FkZWRGaWxlOjpnZXRJbnN0YW5jZSgkbW9kZWwsICdpbWFnZScpOwoJICAgICAgICBpZigkbW9kZWwtPnNhdmUoKSl7CgkJICAgICAgICAkbW9kZWwtPmltYWdlLT5zYXZlQXMoJ2ltYWdlcycpOwoJCSAgICAgICAgJHRoaXMtPnJlZnJlc2goKTsKCQkgICAgfQoJCX0KCSAgICAkdGhpcy0+cmVuZGVyKCdjcmVhdGUnLCBhcnJheSgnbW9kZWwnPT4kbW9kZWwpKTsKICAJfQp9