2017-03-07
In the development, I encountered a front-end when uploading images, using the Base64 data stream file to display the picture.
Other words
image/behind the JPG is our image File format, (base64,) behind a very long string is the specific file information.
Data:image/jpg;base64 refers to the file header. We can put all the contents of SRC into the address bar of the browser.
The image file can be displayed normally.
After I get the value of SRC to the background, I handle it in the background. The method here is not specifically detailed.
$base _img is the value that gets into the src of the front-end pass, which is our data stream file $base_img = Str_replace (' data:image/jpg;base64, ', ', $base _img);// set file path and file prefix name $path = "./"; $prefix = ' nx_ '; $output _file = $prefix. Time (). Rand (100,999). JPG '; $path = $path. $output _file;// Create to write the data stream file to the contents of the file we created $IFP = fopen ($path, "WB"); Fwrite ($IFP, Base64_decode ($ BASE_IMG) fclose ($IFP);///File_put_contents ($path, Base64_decode ($base _img));//Output File Print_r ($output _file) ;
Online conversion Tool Links: http://tool.css-js.com/base64.html
Base64 Introduction: Http://baike.baidu.com/link?url=tbfs2Rem2mqO8ZLe91jp9BhLQJqBEvjDHFzu05lF4DxUoqNSdS9pzqoHuYrzPvxQZr_ Zioc1bs7-zok364yp5_
How does PHP convert base64 data stream files to picture files?