public function multi_imgupload()
{
$jsdata = html_entity_decode($_POST["jsdata"]);
$jsdatass = json_decode($jsdata, true);
$data=array();
$msg="";
$code="0";
if($jsdatass) {
foreach ($jsdatass as $key => &$value) {
$imgname = $value['imgname'];
$imgbase64 = $value['imgbase64'];
if (preg_match('/^(data:\s*image\/(\w+);base64,)/',$imgbase64,$result)){
$type = $result[2];
$new_file =ROOT_PATH . 'attachs' . DS ;
$url='/ueditor/imagebase64/'. date("Ymd", time()) . "/";
$new_file=$new_file.$url;
if (!file_exists($new_file)) {
mkdir($new_file, 0777,true);
}
$filename = time() . '_' . uniqid() . ".{$type}";
$new_file = $new_file . $filename;
$url=$url.$filename;
if(file_put_contents($new_file, base64_decode(str_replace($result[1], '', $imgbase64)))) {
$data_img = array();
$data_img['imgurl'] = $url;
$data_img['imgname'] =$imgname;
$data_img['create_time'] = time();
$pid = Db::table("wxb_imgurlknowledge")->insertGetId($data_img);
$arr = array("url" => $url, "id" => $pid);
$url_top = 'http://';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$url_top = 'https://';
}
$url=$url_top.$_SERVER['HTTP_HOST'].'/attachs'.$url;
$code="1";
$msg="上传成功";
$data[]=array('name'=>$imgname,'url'=>$url);
}
}
}
}
else
{
$code="0";
$msg="上传失败,图片参数为空,请上传图片";
}
return $this->result($data, $code, $msg, 'json');
}
|