/** * 创建,修改故事 */ public function actionCreate() { ini_set('upload_max_filesize', '20M'); ini_set('post_max_size', '20M'); ini_set('max_input_time', 300); ini_set('max_execution_time', 300); //if(!isset($_POST)) $this->sendErrorResponse(403); //修改哈 if (isset($_POST['sid'])) { $model = Story::model()->findByPk($_POST['sid']); } else { $model = new Story(); //新建 $model->share_num = $model->view_num = $model->like_num = 0; } $model->createtime = time(); $model->uid = $_POST['uid']; $model->description = isset($_POST['description']) ? $_POST['description'] : ''; $model->rec_status = isset($_POST['rec_status']) ? $_POST['rec_status'] : ''; $model->small_img = isset($_POST['small_img']) ? $this->saveStrToImg(trim($_POST['small_img'])) : ''; $model->story_name = $_POST['story_name']; if (isset($_FILES['zip_file']['tmp_name'])) { $target_path = "html/"; $target_path = $target_path . $_POST['uid'] . '/' . date('YmdHi'); $zipPath = $target_path . '/' . $_FILES['zip_file']['name']; if (!is_dir($target_path)) { $this->mkdirs($target_path); } // $this->sendErrorResponse(404,$target_path); try { if (!move_uploaded_file($_FILES['zip_file']['tmp_name'], $zipPath)) { $this->sendErrorResponse(403); } $zip = Yii::app()->zip; if ($zip->extractZip($zipPath, $target_path)) { if (!unlink($zipPath)) { $this->sendErrorResponse(500, 'del zip error'); } $model->story_url = SITE_URL . '/' . $target_path; } else { $this->sendErrorResponse(500, 'zip file extract error'); } } catch (Exception $e) { $this->sendErrorResponse(403, $e->getMessage()); } } if (!$model->save()) { $this->sendErrorResponse(403); } $this->sendDataResponse($model->getAttributes()); }