php Save Binary Original Data for Picture Program Code
- 2021-07-21 07:55:46
- OfStack
Get the binary original data from post, select a generation path and the name of the picture, and then write it. The idea is obvious
// Generate a picture
$imgDir = 'uploadImg/';
$filename="nissangcj".$mobile.".jpg";/// The name of the picture to be generated
$xmlstr = $GLOBALS[HTTP_RAW_POST_DATA];
if(empty($xmlstr)) {
$xmlstr = file_get_contents('php://input');
}
$jpg = $xmlstr;// Get post Come over 2 Binary raw data
if(empty($jpg))
{
echo 'nostream';
exit();
}
$file = fopen("./".$imgDir.$filename,"w");// Open the file for writing
fwrite($file,$jpg);// Write
fclose($file);// Shut down
$filePath = './'.$imgDir.$filename;
// Does the picture exist
if(!file_exists($filePath))
{
echo 'createFail';
exit();
}