$params = json_decode(file_get_contents('php://input'), TRUE);
$files = $params['files'];
$paths=array();
foreach ($files as $imgbase64) {
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $imgbase64, $result)) {
$type = $result[2];//图片后缀
$url = '../upload/tip/' . date("Ymd", time()) . "/";
$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;
//写入操作
$paths[]= $url;
file_put_contents($new_file, base64_decode(str_replace($result[1], '', $imgbase64)));
}
}
var_dump($paths);return;
前端post传参files内容是['data:image/jpeg;base64,iVB...','data:image/jpeg;base64,iVB...','data:image/jpeg;base64,iVB...']