$param = file_get_contents("php://input");
$param = explode("&", $param);
$headimg = explode("=", $param[2])[1];
$user_id = explode("=", $param[3])[1];
$param2 = str_replace(" ", "+", $headimg);
$param2 = str_replace("%2F", "/", $param2);
$param2 = str_replace("%2B", "+", $param2);
$param2 = str_replace("%0A", "", $param2);
$headData =base64_decode($param2);
$imgName = time() . mt_rand(0, 9) . '.jpg';
$imgUrl = 'data/headimg/' . date('Ym') . '/' . $imgName;
$path='../data/headimg/' . date('Ym') . '/';
if (!file_exists($path)) {
mkdir("$path", 0777, true);
}
$result = file_put_contents($path.$imgName, $headData);
$sql=" SELECT headimg FROM ".$ecs->table("users")." WHERE user_id='$user_id'";
$data=$db->getOne($sql);
@unlink("../".$data);
$sql = 'UPDATE ' . $ecs->table('users') . " SET headimg='$imgUrl' WHERE user_id='" . $user_id . "'";
$result = $db->query($sql);
php base64_decode 接收图片处理
最新推荐文章于 2021-04-08 20:22:37 发布