哦
wkvnh06ccoac 2018-5-26
namespace app\home\controller; use app\home\controller\Common; class Upload extends Common{ public function _empty(){ phpinfo(); } public function image(){ $fileExt=['gif','jpeg','jpg','png']; $MaxfileSize=1024*1024*2; if(isset($_FILES["file"])){ $extension=pathinfo($_FILES["file"]['name'])['extension']; if($_FILES['file']['size']==0){ $this->error('未知系统错误'); return ; } if(!in_array($extension,$fileExt)){ $this->error('只支JPG/GIF/PNG/JPEG文件'); return ; } if($_FILES['file']['size']>=$MaxfileSize){ $this->error('图片大小不能超过2MB'); return ; } //临时文件保存目录 $ImageCachePath=RUNTIME_PATH.'image/';//缓存路径 if(!is_dir($ImageCachePath)){//不存在,创建文件夹 mkdir($this->path, 777, true); } //生成新文件名 $newFileName=$ImageCachePath.md5(rand(10000,99999)).'.'.$extension; //把文件存入临时目录 if(!move_uploaded_file($_FILES["file"]["tmp_name"],$newFileName)){ unlink($newFileName); $this->error('上传失败!代码100'); return ; } //接口地址 $UploadUrl = 'http://pic.sogou.com/ris_upload?r='.rand(10000,99999); //取出临时目录上传的文件 $curlPost = array('pic_path'=>new \CurlFile($newFileName)); //模拟上传开始 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $UploadUrl); // curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); //POST提交 curl_setopt($ch, CURLOPT_POSTFIELDS,$curlPost); $data =curl_exec($ch); curl_close($ch); //Urldecode解码字符串 $NewData=urldecode($data); //匹配出结果 preg_match('/query\=(.*?)\&oname/i',$NewData,$ImageUrl); if(!isset($ImageUrl[1])){ unlink($newFileName); $this->error('上传失败!代码200'); return ; } //返回Url,并且删除文件 unlink($newFileName); $this->success('上传成功!',$ImageUrl[1]); return ; } } }
昨天无意间发现的。然后自己按照借口写了写了个脚本。
交流一下
ah9jyxotx6xj# 1楼 2018-9-21 点评 哦 |