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: tool.css-js.com/base64.html
The above is the details of how PHP will convert the Base64 data stream file into a picture file, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!