yii实现图片上传及缩略图生成的方法(2)

<?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()?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/5758ec8b52910d8ee1b35d457c97e889.html