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

yipeiwu_com6年前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(); 
  } 

相关文章

随时给自己贴的图片加文字的php水印

随时给自己贴的图片加文字  <?  Header( "Content-type: image/jpeg");  function&...

php实现生成code128条形码的方法详解

php实现生成code128条形码的方法详解

本文实例讲述了php实现生成code128条形码的方法。分享给大家供大家参考,具体如下: 效果图: <?php class BarCode128 { const...

php获取URL中带#号等特殊符号参数的解决方法

例如下面的PHP代码: 复制代码 代码如下: <?php echo $_GET['key']; ?> 当url为http://test.com/c.php&...

PHP严重致命错误处理:php Fatal error: Cannot redeclare class or function

1、错误类型:PHP致命错误 Error type: PHP Fatal error Fatal error: Cannot redeclare (a) (previously decl...

如何在php中正确的使用json

从5.2版本开始,PHP原生提供json_encode()和json_decode()函数,前者用于编码,后者用于解码。 1、json_encode()该函数主要用来将数组和对象,转换为...