图像转数据流asp&php 's

admin 2017年4月15日08:39:17评论275 views字数 1652阅读5分30秒阅读模式
摘要

来源:vbs小铺asp图像转数据流:<%Function ReadGif(sStr)
Dim i, iHex, sPath, oStream
sPath = Server.MapPath(sStr)
Set oStream = Server.CreateObject("Adodb.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sPath

来源:vbs小铺

asp图像转数据流:

<%Function ReadGif(sStr)
Dim i, iHex, sPath, oStream
sPath = Server.MapPath(sStr)
Set oStream = Server.CreateObject("Adodb.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sPath

For i = 1 To LenB(oStream.Read())
oStream.Position = 0
iHex = Hex(AscB(MidB(oStream.Read(), i, 1)))
If Len(iHex) = 1 Then iHex = "0" & iHex
ReadGif = ReadGif & iHex
Next

oStream.Close
Set oStream = Nothing
End Function
%>
<%=ReadGif("help.gif")%>

图像转数据流转ASP

<%

WriteGif("上边的函数转的字符串全部放进来就可以了")

Sub WriteGif(sStr)
Dim aAry
Response.Clear
aAry = MySplit(sStr)
Response.ContentType = "image/gif"
For i = 0 To UBound(aAry)
Response.BinaryWrite ChrB("&H" & aAry(i))
Next
End Sub

Function MySplit(sStr)
Dim sTmp

For i = 1 To Len(sStr) Step 2
sTmp = sTmp & Mid(sStr, i, 2) & ","
Next
If sTmp <> "" Then sTmp = Left(sTmp, Len(sTmp) – 1)

MySplit = Split(sTmp, ",")
End Function
%>

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
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']);
}
?>

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2017年4月15日08:39:17
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   图像转数据流asp&php 'shttps://cn-sec.com/archives/46712.html

发表评论

匿名网友 填写信息