public function actionEditconfig($cid) { $configModel = Config::model(); $configInfo = $configModel->findByPk($cid); $configInfotmp = $configInfo; Yii::import('application.vendors.*'); require_once 'Qiniu/rs.php'; require_once 'Qiniu/io.php'; $bucket = Yii::app()->params['bucket']; $accessKey = Yii::app()->params['accessKey']; $secretKey = Yii::app()->params['secretKey']; if (isset($_POST['Config'])) { $post = $_POST['Config']; $configInfo->attributes = $post; if ($configInfo->validate()) { $images = ""; if (!empty($_FILES['icon']['tmp_name'])) { $file = $_FILES['icon']; $type = ".jpg"; if (ImageTypeCheck($file['name'], $file['size'])) { $newname = time() . rand(10000, 99999) . $type; Qiniu_SetKeys($accessKey, $secretKey); $putPolicy = new Qiniu_RS_PutPolicy($bucket); $upToken = $putPolicy->Token(null); list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name']), null); if ($err === null) { //ok $images = Yii::app()->params['resurl'] . $newname; } else { //no } } //Get original Pic and Del $icon = GetImageFileName($configInfotmp->icon); if (!empty($icon)) { Qiniu_SetKeys($accessKey, $secretKey); $client = new Qiniu_MacHttpClient(null); $err = Qiniu_RS_Delete($client, $bucket, $icon[0]); } } else { $images = $configInfo->icon; } $configInfo->icon = $images; if (!$configInfo->save()) { Yii::app()->user->setFlash('state', "Sorry,系统错误,修改配置失败 :("); } else { $this->redirect(array('webconfig')); } } } $data = array('editModel' => $configInfo); $this->render('editconfig', $data); }
public function actionEditblog($id) { $label = new Article(); $labels = $label->findAll('userid=:uid', array(':uid' => Yii::app()->session['uid'])); //$labesArray是对应于id,label键值的一维数组 $labesArray[0] = '--请选择--'; foreach ($labels as $l) { $labesArray[$l->id] = $l->label; } $blog = Blog::model(); $blogInfo = $blog->findByPk($id); $blogInfotmp = $blogInfo; //存储到session[blogid] 防止imageUP后台处理时有添加一条记录到blog表中 Yii::app()->session['blogid'] = $id; //七牛上传类 Yii::import('application.vendors.*'); require_once 'Qiniu/io.php'; require_once 'Qiniu/rs.php'; $bucket = Yii::app()->params['bucket']; $accessKey = Yii::app()->params['accessKey']; $secretKey = Yii::app()->params['secretKey']; if (isset($_POST['Blog'])) { $post = $_POST['Blog']; //$post['view'] = 0; $post['time'] = time(); $post['userid'] = Yii::app()->session['uid']; $blogInfo->attributes = $post; if ($blogInfo->validate()) { /** * 处理图片 * require_once 'UPimage/UPimage.php'; //图片缩略类 * $resizeimage = new resizeimage("1.jpg", "320", "240", "1","2.jpg"); * 1.缩略图 * 2.文章图片 删除就行 添加记录由后台异步处理 //删除文章时处理 */ //echo CheckUploadFiles($_FILES['thumb']);die; //1 //a 查出缩略图片并 b删除七牛上的图片 传递一个特殊的字符串 $images = ""; //拼接图片以@方式 if (CheckUploadFiles($_FILES['thumb'])) { //删除图片 $file = $_FILES['thumb']; $type = ".jpg"; if (count($file['name']) != 0) { foreach ($file['name'] as $key => $f) { if (ImageTypeCheck($file['name'][$key], $file['size'][$key])) { $newname = time() . rand(10000, 99999) . $type; Qiniu_SetKeys($accessKey, $secretKey); $putPolicy = new Qiniu_RS_PutPolicy($bucket); $upToken = $putPolicy->Token(null); list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name'][$key]), null); if ($err === null) { //成功 $images .= "http://" . Yii::app()->params['bucket'] . "." . Yii::app()->params['domain'] . "/" . $newname . "@"; } else { //失败 } } } } //删除图片 $imgs = GetImageFileName($blogInfotmp->image); Qiniu_SetKeys($accessKey, $secretKey); $client = new Qiniu_MacHttpClient(null); foreach ($imgs as $i) { if (!isset($client)) { $client = new Qiniu_MacHttpClient(null); } $err = Qiniu_RS_Delete($client, $bucket, $i); } } else { //没有上传图片 不做任何操作 保持原来的图片 $images = $blogInfo->image; } //$post['image'] = $images; $blogInfo->attributes = $post; //2 //删除文章文字配图 和业务数据库中的记录 // Qiniu_SetKeys($accessKey, $secretKey); // $client = new Qiniu_MacHttpClient(null); // $imgageModel = Image::model(); // $textImage = $imgageModel->findAll('blogid=:bid',array('bid'=>$id)); // foreach ($textImage as $ti){ // if(!isset($client)) // $client = new Qiniu_MacHttpClient(null); // // $err = Qiniu_RS_Delete($client, $bucket, $ti->image); // } // $imgageModel->deleteAll('blogid=:bid',array('bid'=>$id)); $blogInfo->image = $images; $blogInfo->content = $_POST['content']; if ($blogInfo->save()) { /** * 注销blogid 必须的 */ Yii::app()->session['blogid'] = null; Yii::app()->user->setFlash('sendblogsuccess', '修改文章成功 :)'); $this->redirect(array('articles')); } } } $data = array('labels' => $labesArray, 'blogModel' => $blogInfo); $this->render('editblog', $data); }