<?php
class Upload extends CFormModel {
public $file;
public function rules() {
return array(
array('file', 'file', 'types' => 'jpg, gif, png,zip'),
);
}
}
图片显示页面:
自定义图片大小,缩略图自动生成
复制代码 代码如下:
<?php
/**
* list.php
* Created on: 2014-1-26 13:12:01 by Outsider
*/
?>
<?php foreach ($list as $v): ?>
<img src="<?php echo Yii::app()->createUrl('test/getThumb', array('path' => '/uploads' . $v['path'], 'w' => '150', 'h' => '150')) ?>">
<?php endforeach; ?>
图片上传表单:
复制代码 代码如下:
<?php if($uploaded):?>
<p>File was uploaded. Check <?php echo $dir?>.</p>
<?php endif ?>
<?php echo CHtml::beginForm('','post',array
('enctype'=>'multipart/form-data'))?>
<?php echo CHtml::error($model, 'file')?>
<?php echo CHtml::activeFileField($model, 'file')?>
<?php echo CHtml::submitButton('Upload')?>
<?php echo CHtml::endForm()?>