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 expects parameter 1 to be resource, array given 错误

如果你使用的是封装好的类 例如 function fetch_array($query, $result_type = MYSQL_ASSOC) { return mysql_fetch...

php相对当前文件include其它文件的方法

本文实例讲述了php相对当前文件include其它文件的方法。分享给大家供大家参考。具体分析如下: 下面的代码先获得当前文件路径,然后通过相对路径包含其它php文件,在实际使用中非常有用...

Thinkphp无限级分类代码

Thinkphp无限级分类代码

本篇就一点一点教大家写一个无限级分类出来,其实掌握一个知识,最主要的是要掌握无限级分类的逻辑,那么写起来就很容易的多了。 首先看数据库表:xp_cate 控制器:CateAction....

Fatal error: Call to undefined function curl_init()解决方法

首先要确定php已经扩展 在php.ini中 复制代码 代码如下: extension=php_curl.dll 还要保证 php_curl.dll 复制到php安装目录下的ext下,...

Laravel实现autoload方法详解

Laravel实现autoload方法详解

用了一阵Laravel后发现很少有include和require,觉得有点奇怪,思考Laravel是怎么完成文件导入的。 其实Laravel依旧还是用include或者require的,...