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
Release: 2016-07-13 10:17:18
Original
823 people have browsed it

php program code for saving binary raw data as images

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

//生成图片 

$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(); 

}

1 2 3

4

6 7 8 9 10
11 12
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//Generate pictures $imgDir = 'uploadImg/'; $filename="nissangcj".$mobile.".jpg";///The name of the image to be generated $xmlstr = $GLOBALS[HTTP_RAW_POST_DATA]; if(empty($xmlstr)) { $xmlstr = file_get_contents('php://input'); } $jpg = $xmlstr;//Get the binary original data posted if(empty($jpg)) { echo 'nostream'; exit(); } $file = fopen("./".$imgDir.$filename,"w");//Open the file for writing fwrite($file,$jpg);//Write fclose($file);//Close $filePath = './'.$imgDir.$filename; //Does the picture exist? if(!file_exists($filePath)) { echo 'createFail'; exit(); }
http://www.bkjia.com/PHPjc/894051.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/894051.htmlTechArticlephp program code to save binary raw data as images to get the binary raw data posted, select a generation path and image The name is written later, the idea is very obvious...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template