服务器端php获取图片数据流

WBOY
Release: 2016-06-20 12:55:36
Original
1885 people have browsed it

<?php$base64 = file_get_contents("php://input"); //获取输入流$base64 = json_decode($base64,1);$data = $base64['base64'];preg_match("/data:image\/(.*);base64,/",$data,$res);$ext = $res[1];if(!in_array($ext,array("jpg","jpeg","png","gif"))){echo json_encode(array("error"=>1));die;}$file = time().'.'.$ext;$data = preg_replace("/data:image\/(.*);base64,/","",$data);if (file_put_contents($file,base64_decode($data))===false) {echo json_encode(array("error"=>1));}else{echo json_encode(array("error"=>0));}
Copy after login




source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!