Regarding the method of saving binary raw data as image files in PHP, receive the binary raw data posted, select a generation path and the name of the image, and then write it, friends who need it can refer to it.
Example, php saves binary raw data into image files. //生成图片 $imgDir = 'uploadImg/'; $filename="nissangcj".$mobile.".jpg"; ///要生成的图片名字 $xmlstr = $GLOBALS[HTTP_RAW_POST_DATA]; if(empty($xmlstr)) { $xmlstr = file_get_contents('php://input'); } $jpg = $xmlstr; //得到post过来的二进制原始数据 if(empty($jpg)) { echo 'nostream'; exit(); } // bbs.it-home.org $file = fopen("./".$imgDir.$filename,"w"); //打开文件准备写入 fwrite($file,$jpg);//写入 fclose($file);//关闭 $filePath = './'.$imgDir.$filename; //图片是否存在 if(!file_exists($filePath)) { echo 'createFail'; exit(); } Copy after login |