|
|
PHP图像转数据流
作者: hopol 来源:互联网
PHP代码
- <?
- function mgReadFile($fileName)
- {
- if(is_readable($fileName))
- {
- $handle = fopen($fileName,'rb');
- if(flock($handle,LOCK_SH))
- {
- $data = fread($handle,filesize($fileName));
- fclose($handle);
- return $data;
- }
- else
- {
- throw new MagikeException(E_FILEOPERATIONFAIL,'Unable To Unblock '.$fileName);
- }
- }
- else
- {
- throw new MagikeException(E_FILEOPERATIONFAIL,'Unable To Read '.$fileName);
- }
- return NULL;
- }
- //$val='c:/1.jpg';
-
//$data=base64_encode(addslashes(fread(fopen($val, "r"), filesize($val))));
- $data=base64_encode(mgReadFile('c:/1.jpg'));
- echo $data
- ?>
图像转数据流转PHP,调用.php?img=gril
PHP代码
- <?php
- function showImage($img)
- {
- $images = array(
- 'gril' => array(
- 'type' => 'gif',
- 'data' => '上边的函数转的字符串全部放进来就可以',
- ),
- );
-
- Header('Content-Type: image/'.$images[$img]['type']);
- echo base64_decode($images[$img]['data']);
- };
- if ($_GET['img']){
- showImage($_GET['img']);
- }
- ?>
|