Home >Backend Development >PHP Tutorial >PHP program code to save binary raw data as images, _PHP tutorial

PHP program code to save binary raw data as images, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:13983browse

PHP program code for saving binary raw data into images,

Get the binary raw data posted, choose a generation path and the name of the image, and then write it, the idea is obvious

  //生成图片 
  $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(); 
  } 
   
  $file = fopen("./".$imgDir.$filename,"w");//打开文件准备写入 
  fwrite($file,$jpg);//写入 
  fclose($file);//关闭 
   
  $filePath = './'.$imgDir.$filename; 
   
  //图片是否存在 
  if(!file_exists($filePath)) 
  { 
    echo 'createFail'; 
    exit(); 
  } 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/894136.htmlTechArticlephp program code to save binary raw data as images, get the binary raw data posted, select a generation path and Write the name of the picture later, the idea is very obvious...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn