PHP Soap二进制映像问题


PHP Soap binary image issue

我有一个iPhone的web服务。我从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); }

文件有签名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);
}