1、接收一个post请求,获取密码如果正确则添加到本地数据中
2、curl_post方法
public static function curl_post($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 我们在POST数据哦! curl_setopt($ch, CURLOPT_POST, 1); // 把post的变量加上 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; }
3、图片接口
/*上传图片接口测试*/ public function actionMypic(){ //‘pic‘ => ‘@‘.realpath(‘./mypic.png‘).‘;type=image/png‘ $file = realpath(mb_convert_encoding(‘/data/www/en/protected/controllers/test.jpg‘,‘GBK‘,‘utf8‘)); $file = realpath(‘/data/www/en/protected/controllers/test.jpg‘); //要上传的文件 $key=md5("mypic"."lcc"); $post_data = array ( "news_key" => $key, "news_name"=>"mypic", // 要上传的本地文件地址 "uploads" => ‘@‘.$file ); $re = self::curl_post2("testmetal.smm.cn/interface/smm_news_pic_add_industry/", $post_data); echo ‘<pre>‘; print_r($re) ; }
4、控制器
/* * 上传图片接口 * 从行业库上传图片到本地服务器 * 2015-06-19 lcc */ public function actionSmm_news_pic_add_industry() { if($_POST){ //print_r($_POST);die(); $key=md5($_POST[‘news_name‘]."lcc"); $news_key=$_POST[‘news_key‘]; if($key!=$news_key){ echo ‘false‘; } $image = CUploadedFile::getInstanceByName(‘uploads‘); $dir=Yii::getPathOfAlias(‘webroot‘).‘/Upload/lcc/‘;//上传目录 $name = $dir.‘lcc_‘.time().‘.‘.$image->getExtensionName(); //文件名绝对路径 $status = $image->saveAs($name,true); //保存文件 if ($status) { echo $name; }else { echo ‘false‘; } }else{ echo ‘false‘; } }
时间: 2024-10-10 21:04:42