fwrite() - 写入png后图像可能会损坏

时间:2014-07-22 03:54:49

标签: php fwrite

我正在尝试将图像下载到服务器然后发送到客户端进行本地下载,图像数据将来自谷歌图表。 (谷歌图表目前不支持'下载图表为图像')。

它现在正在下载到服务器但我无法打开它,它说:

"It may be damaged or use a file format that Preview doesn’t recognize."` 

我正在使用Mac )。

我应该解码吗?我不知道,需要你的帮助。

这是我的代码:

的JavaScript

$.post('ajaxrequest.php', {
    func: 'saveImageToServer',
    case: imgData,
    param: 'sample001001'
    }, function(data){
        console.log(data);
});

PHP:

if($request == 'saveImageToServer') {
    //Get the file
    $image = $case;

    // write it
    $filename = $param;
    $file = "./downloadedcharts/".$filename.".png";

    $fh = fopen($file, 'w') or die("can't open file");

    if(fwrite($fh, $image)) {
        fclose($fh);
        echo "download success";
    } else {
        echo "error";   
    }

}

以下是我传递的图像数据示例:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVIAAADYCAYAAAC5iWvlAAAgAElEQVR4Xu2dC5hWRRnHX+QuC4KGJhJGhXgXXW5GZGpKCipmWal54y4SEchFQ7l4IZDAEGQXFLkY4C2jBCVFxc3KZcEwEZISQkjzFoTAokb7Hz3bB+73fXPmzLnN95/n8Xlkv5l5Z/4z8zsz78ycU2tfVRAGKkAFqAAVMFagFkFqrB0TUgEqQAWUAgQpOwIVoAJUIKACBGlAAZmcClABKkCQsg9QASpABQIqQJAGFJDJqQAVoAIEKfsAFaACVCCgAgRpQAGZnApQASpAkLIPUAEqQAUCKkCQBhSQyakAFaACBCn7ABWgAlQgoAIEaUABmZwKUAEqQJCyD1ABKkAFAipAkAYUkMmpABWgAgQp+wAVoAJUIKACBGlAAZmcClABKkCQsg9QASpABQIqQJAGFJDJqQAVoAIEaVUf2Lhxo7Rp06a6NzRu3Fhmz54tl156qVYP2bNnj3Tq1Emuv/566dq1q3Ts2FE2b94szZo1q06fGadPnz5a+TISFaAC6VCAIM0A6c033yzHHXec3H333bJ27VrZsGGDHHnkkXlb8sMPP5T27dt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EgcX8IRNrwPwduVB2QR4CvFAft811FrqmNUdjzbUfU3k/ZkmnAViAWkmVXC8SbMorAj670mDL68e++9V81KsCOrcywnn0yu2UF9sfmCN/54Dxosx/HAwR1saAag2gi27QBwuAaJXXeAFG9m+sc//qFWI2gnHGvD7BofJMTZUJw00HXlZNY3Kjs1aRxVf7PRvswjuAKxgxRvq8duM+7H45gIdoaD7Mhnk8Q1O6gndMPda+xs48Uc8J2G8RXUsO1g1YElvHcGGO83wIMUZ2DxID3mmGOC9/SqHKKyg8JG1d+sCMNMAisQO0jxdiZsmmApCn8fXsCbeac+cA0/zcA1O6gW3mSE86KYeeJb7ABqGCFMO5l+xR07dqglPl5zZztEZccrd1T9zbZOzM9MgVhB6p1txMF77C5/85vf1NpA8FtV1+x49Z82bZp6iTU2n0x8yLo6hmkHx7GwcQY/KK534qYazpHaDlHZQbmj6m+2NWJ+5grEClIUG8t5vKEcb3EKM7hmJ0ytoswb35LH94dwUgMbZ3j9XRghKjte2aPqb2FoxTz9KxA7SP0XmSlcUgB35HHMyXtTf1h1i8pOWOVnvslWgCBNdvuwdFSACqRAAYI0BY3EIlIBKpBsBQjSZLcPS0cFqEAKFCBIU9BILCIVoALJVoAgTXb7sHRUgAqkQAGCNAWNxCJSASqQbAX+B2ZQN+/obVt5AAAAAElFTkSuQmCC`

2 个答案:

答案 0 :(得分:1)

就像杰克所说,在我的服务器上,PHP创建了损坏的文件,我只添加了行

stream_filter_append($imagen, 'convert.base64-decode');
在fwrite()函数之前的

一切正常

答案 1 :(得分:0)

您不能将base64编码数据写入文件并期望它能够正常工作;它需要先解码:

$f = fopen('output.png', 'wb');
stream_filter_append($f, 'convert.base64-decode');
fwrite($f, substr($case, strpos($case, ',') + 1));
fclose($f);