Home >Backend Development >PHP Tutorial >PHP program code to save binary raw data as images_PHP tutorial
Get the posted binary raw data, choose a generation path and the name of the image, and then write it, the idea is obvious
4 11 12 |
//Generate pictures $imgDir = 'uploadImg/'; $filename="nissangcj".$mobile.".jpg";///The 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 original data posted if(empty($jpg)) { echo 'nostream'; exit(); } $file = fopen("./".$imgDir.$filename,"w");//Open the file for writing fwrite($file,$jpg);//Write fclose($file);//Close $filePath = './'.$imgDir.$filename; //Does the picture exist? if(!file_exists($filePath)) { echo 'createFail'; exit(); } |