PHP到Coldfusion zip / pkpass输出流

时间:2017-07-11 03:52:44

标签: php coldfusion coldfusion-10 coldfusion-11 lucee

这个项目是苹果钱包项目我有,但在PHP代码我面临的挑战没有太大的帮助可用我的PHP问题是开放没有回应到目前为止,无论如何现在我决定转换为coldfusion。

我能够在BLOB中以二进制文件保存ZIP / PKPASS文件。当我发送PHP API GET请求到获取卡(二进制zip / pkpass)时,它返回二进制流,请参阅下面的附加屏幕。 enter image description here

当我向coldfusion API代码发送请求时,我想在coldfusion中实现相同的结果。

邮差: enter image description here

火狐: enter image description here

我试图在coldfusion(lucee)中转换PHP代码。数据库中的二进制代码是zip文件,但扩展名为“.pkpass”,数据库字段名称为“data”。

当我运行coldfusion代码时,它给出错误“Corrupted Content Error”。

PHP代码:

 $myPass = $result->fetch();

        $data = $myPass['data']; //zip/pkpass file Binary code from DB
        $nameFile = 'passbook_'.time().'.pkpass';
        file_put_contents($nameFile, $data);

        $stream = function () use ($nameFile) {
            readfile($nameFile);
        };

        return $app->stream($stream, 200, array(

            'Pragma' =>  'no-cache',
            'Cache-Control' => 'private,false',
            'Content-Transfer-Encoding' =>  'binary',
            'Content-Disposition' => 'inline; filename="'.basename($nameFile).'"',
            'Content-Type' => 'application/vnd.apple.pkpass',
            'Content-length' => filesize($nameFile),
            'Content-Disposition' => 'attachment; filename="'.$nameFile.'"',
            'Last-Modified' => gmdate('D, d M Y H:i:s T')
        ));

Coldfusion代码:不工作需要帮助

   <cfset filename = getPass.serial_number&'_'&createUUID()&'.pkpass'>  
            <cfheader name="Pragma" value="no-cache">
            <cfheader name="Cache-Control" value="private,false">
            <cfheader name="Content-Transfer-Encoding" value="binary">
            <cfheader name="Content-Disposition" value="inline; filename=#filename#">
            <cfheader name="Content-Type" value="'application/vnd.apple.pkpass">
            <cfheader name="Content-Disposition" value="attachment; filename=#filename#">
            <cfheader name="Content-Disposition" value="#DateFormat(getPass.updated_at, "yyyy-mm-dd")#' '#TimeFormat(getPass.updated_at, 'hh:mm:ss')#">
<cfcontent type="application/x-zip-compressed" variable="#BinaryDecode(getPass.data, 'Base64')#"> <!--- Binary Data from db 'getPass.data' --->

1 个答案:

答案 0 :(得分:2)

主要问题似乎是您将最后修改的值放在“Content-Disposition”标题中。尝试修复并清理其他标题,如下所示:

<cfscript>
filename = "#getPass.serial_number#_#CreateUUID()#.pkpass";
cfheader( name="Pragma", value="no-cache" );
cfheader( name="Cache-Control", value="private,false" );
cfheader( name="Last-Modified", value="#DateFormat( getPass.updated_at, 'yyyy-mm-dd' )# #TimeFormat( getPass.updated_at, 'hh:mm:ss' )#" );
cfheader( name="Content-Transfer-Encoding", value="binary" );
cfheader( name="Content-Disposition", value="attachment; filename=#filename#" );
cfcontent( variable="#getPass.data#", type="application/vnd.apple.pkpass" );
</cfscript>