Home > php教程 > php手册 > body text

php保存二进制原始数据为图片的程序代码,

WBOY
Release: 2016-06-13 09:24:03
Original
987 people have browsed it

php保存二进制原始数据为图片的程序代码,

得到post过来的二进制原始数据,选择一个生成路径及图片的名字,之后写入,思路很显而易见

  //生成图片 
  $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(); 
  } 
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template