yk19880829
回复才能看到
- yk19880829 回复了话题 YII写的网络公司CMS站(原创)
我晕我删什么了! 我说的很明白,我只是把前端HTML视图删掉没放出来! 其他代码全部齐全!:L
- yk19880829 回复了话题 想找高手联合开发项目
路过看看:D
- yk19880829 回复了话题 YII下数据库备份与还原类
视图文件:data_back.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <HTML xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo Yii::app()->name;?></title> <meta name="keywords" content="<?php echo Yii::app()->name;?>" /> <meta name="description" content="<?php echo Yii::app()->name;?>" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link type="text/css" rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/style/admin/css/common.css" /> </head> <body> <strong>当前位置:</strong>后台管理—>数据备份 <table width="100%" border="1" align="center" cellpadding="8" cellspacing="1" bordercolor="#CFCFCF" style="margin-top:8px;"> <tr> <td colspan="6" background="<?php echo Yii::app()->request->baseUrl; ?>/style/admin/images/tbg.gif">说明:点击备份可将所有的数据表结构和数据完全备份到项目protected/data/backup/目录下(Linux下注意将此目录权限设置为777) </td> </tr> <tr bgcolor="#f4fbf4" height="22"> <td height="26" align="center" bgcolor="#FAFAF1" ><span class="STYLE1">备份记录</span></td> <td height="26" align="center" bgcolor="#FAFAF1" >文件大小</td> <td height="26" align="center" bgcolor="#FAFAF1" >备份日期</td> <td height="26" align="center" bgcolor="#FAFAF1" >基本操作</td> </tr> <?php foreach($data as $val){ ?> <tr onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22" > <td width="32%"><?php echo $val['name']; ?></td> <td width="17%" align="center"><?php echo $val['size']; ?></td> <td width="28%" align="center"><?php echo $val['time']; ?></td> <td width="23%" align="center"> <?php echo CHtml::link('删除', array('/databack/delete_back', 'file'=>$val['name'] ), array( "title"=>"删除", 'onclick'=>"{if(confirm('您真的要删除吗?')){return true;}return false;}" ) );?> <?php echo CHtml::link('下载', array('/databack/downloadbak','file'=>$val['name']),array("title"=>"点击下载"));?> <?php echo CHtml::link('还原', array('/databack/recover', 'file'=>$val['name'] ), array( "title"=>"还原", 'onclick'=>"{if(confirm('确定要还原吗?')){return true;}return false;}" ) );?> </td> </tr> <?php } ?> <tr onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22" > <td colspan="4" align="center"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'backup-form', 'action'=>$this->createUrl('databack/backup'), )); ?> <?php echo CHtml::submitButton('一键备份',array('class'=>'submit','name'=>'backup')); ?> <?php $this->endWidget(); ?> </td> </tr> </table> </body> </html>
[attach]923[/attach]
写的不好地方,大家有好的建议或者修复即使更帖,谢谢大家多提宝贵意见!当然大家也可以根据自己项目调整即可! - yk19880829 回复了话题 YII下数据库备份与还原类
控制器:DataBackController.php
<?php /** * 功能描述:后台数据备份+还原等操作 * @Author:冰封<574578944@qq.com> * @date:2012-09-03 */ class DataBackController extends Controller { private $config; private $mr; public $layout=false;//设置当前默认布局文件为假 public function __construct(){//初始化相关属性 Yii::import('application.extensions.mysql_back', TRUE);//导入Mysql备份类库 $connect_str = parse_url(Yii::app()->db->connectionString); $re_str = explode('=', implode('=', explode(';', $connect_str['path'])));//取得数据库IP,数据库名 $this->config = array( //设置参数 'host' => $re_str[1], 'dbname'=> $re_str[3], 'port' => 3306, 'db_username' => Yii::app()->db->username, 'db_password' => Yii::app()->db->password, 'db_prefix' => Yii::app()->db->tablePrefix, 'charset' => Yii::app()->db->charset, 'path' => Yii::app()->basePath . '/../protected/data/backup/', //定义备份文件的路径 'isCompress' => 1, //是否开启gzip压缩{0为不开启1为开启} 'isDownload' => 0 //压缩完成后是否自动下载{0为不自动1为自动} ); $this->mr = new mysql_back($this->config); } /** * @显示已备份的数据列表 */ public function actionShow_data(){ $path = $this->config['path']; $fileArr = $this->MyScandir($path); $list = array(); foreach ($fileArr as $key => $value){ if($key > 1){ //获取文件创建时间 $fileTime = date('Y-m-d H:i',filemtime($path . $value)); $fileSize = filesize($path.$value)/1024; //获取文件大小 $fileSize = $fileSize < 1024 ? number_format($fileSize,2).' KB': number_format($fileSize/1024,2).' MB'; //构建列表数组 $list[]=array( 'name' => $value, 'time' => $fileTime, 'size' => $fileSize ); } } $this->render('/site/data_back',array('data'=>$list)); } /** * @备份数据库 */ public function actionBackup(){ $this->mr->setDBName($this->config['dbname']); if($this->mr->backup()){ messages::show_msg($this->createUrl('databack/show_data'), '数据库备份成功!!'); }else{ messages::show_msg($this->createUrl('databack/show_data'), '数据库备份失败!!'); } } /** * @删除数据备份 */ public function actionDelete_back(){ if(unlink($this->config['path'] . $_GET['file'])){ messages::show_msg($this->createUrl('databack/show_data'), '删除备份成功!!'); }else{ messages::show_msg($this->createUrl('databack/show_data'), '删除备份失败!!'); } } /** * @下载备份文件 */ public function actionDownloadbak(){ $this->download($this->config['path'] . $_GET['file']); } /** * @还原数据库 */ public function actionrecover(){ $this->mr->setDBName($this->config['dbname']); if($this->mr->recover($_GET['file'])){ messages::show_msg($this->createUrl('databack/show_data'), '数据还原成功!!'); }else{ messages::show_msg($this->createUrl('databack/show_data'), '数据还原失败!!'); } } /** * @获取目录下文件数组 */ public function MyScandir($FilePath='./',$Order=0){ $FilePath = opendir($FilePath); while($filename = readdir($FilePath)) { $fileArr[] = $filename; } $Order == 0 ? sort($fileArr) : rsort($fileArr); return $fileArr; } /** * @公共下载方法 */ public function download($filename){ ob_end_clean(); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header('Content-Type: application/octet-streamextension'); header('Content-Length: '.filesize($filename)); header('Content-Disposition: attachment; filename='.basename($filename)); readfile($filename); } }
- yk19880829 发布了话题YII下数据库备份与还原类
- yk19880829 回复了话题 25款实用网站后台模板
:o这么多的
呵呵 过段时间我也分享下我写的企业站给大家! 哈哈
- yk19880829 回复了话题 PHP读取谷歌天气API的XML方法
要加精 确实不错!:loveliness: