YII 上传一个图片

YII 中的controller

public function actionUpdate($id){
		$model = $this->loadModel($id);
		if(isset($_POST['Shop'])){
			$model->attributes = $_POST['Shop'];
			$upload=CUploadedFile::getInstance($model,'uploadfile');
			if($upload!=''){
				$url=Upload::createFile($upload,'Shop','create');
				$model->setAttribute('shop_logo', $url);
			}
			$model->save();
			$this->redirect(array('shopmanage/update','id'=>$id));
		}
		$this->render('../shop/shopmanage/update',array(
				'model'=>$model,
		));
	}

YII中的view

<div class="row">
		<?php echo $form->labelEx($model,'shop_logo'); ?>:
		<input type="hidden" name="Shop[uploadfile]" value=""> 
		<input type="file" name='Shop[uploadfile]' style='display: none;' class='uploadfile'>
		<input type='text' name="Shop[shop_logo]" value='<?php echo $model->shop_logo;?>' size='30'>
		<input type='button' value='上传' class='buttonfile'>
		<?php echo $form->error($model,'shop_logo'); ?>
	</div>

YII中的js
$(document).ready(function(){
	
	$('.buttonfile').click(function(){
		$(this).parent().find('.uploadfile').click();
	});
	$('.uploadfile').change(function(){
		$("#shopmanage-form").submit();
	});
})

效果图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值