【问题标题】:PHP Soap binary image issuePHP Soap二进制图像问题
【发布时间】:2011-12-02 23:21:43
【问题描述】:

我有一个适用于 iPhone 的网络服务。我从 iPhone 收到二进制形式的图像。我想问的是我们能否确定以二进制形式发送的图像的扩展名。

我的代码:

$data=base64_decode($data);
$path='event_image/img_out.gif'; /// issue is here
$fp=fopen($path,'w+');
if($fp){ fwrite($fp,$data); fclose($fp); }

【问题讨论】:

标签: php image soap binary


【解决方案1】:

文件有签名http://www.garykessler.net/library/file_sigs.html 您可以从文件的第一行读取并检查。

function output_jpeg($filename)
{
if(($fp = fopen($filename, “rb”)) === false) {
return;
}
$line = fread($fp, 4);
// check the ‘magic number’ of the file
if($line === “\377\330\377\340”) {
fseek($fp, 0);
fpassthru($fp);
}
fclose($fp);
}

【讨论】:

    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2011-08-27
    • 2013-04-03
    相关资源
    最近更新 更多