Php program code for saving Binary Raw data as images
Obtain the Binary Raw Data from post, select a generated path and image name, and write the data to it. The idea is obvious.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
// Generate an image $ ImgDir = 'uploadimg /'; $ Filename = "nissangcj". $ mobile. ". jpg"; // name of the image to be generated $ Xmlstr = $ GLOBALS [HTTP_RAW_POST_DATA]; If (empty ($ xmlstr )){ $ Xmlstr = file_get_contents ('php: // input '); } $ Jpg = $ xmlstr; // get the Binary Raw data after post If (empty ($ jpg )) { Echo 'nostream '; Exit (); } $ File = fopen ("./". $ imgDir. $ filename, "w"); // open the file and write Fwrite ($ file, $ jpg); // write Fclose ($ file); // close $ FilePath = './'. $ imgDir. $ filename; // Whether the image exists If (! File_exists ($ filePath )) { Echo 'createfail '; Exit (); } |