首页 > 解决方案 > base64 编码文件内容给我空响应错误

问题描述

我正在尝试从同一服务器读取文件并尝试使用 Base64 对其进行编码。

尝试使用不同的文件大小,较小的文件可以完美编码,没有错误,但根据我的客户要求,至少 2MB 必须是可以接受的,但现在我最多只能使用大约 750KB。如果我使用超出这个尺寸的任何东西会给我错误。

<?php   
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); 

    $pdf_small = 'https://orangerie.ae/samplefiles/demo-pdf-small.pdf';
    $pdf_normal = 'https://orangerie.ae/samplefiles/demo-pdf-normal.pdf';
    $pdf_high = 'https://orangerie.ae/samplefiles/demo-pdf-high.pdf';
    $pdf_big = 'https://orangerie.ae/samplefiles/demo-pdf-big.pdf';
    $pdf_large = 'https://orangerie.ae/samplefiles/demo-pdf-large.pdf';

    $docx_small = 'https://orangerie.ae/samplefiles/demo-docx-small.docx';
    $docx_normal = 'https://orangerie.ae/samplefiles/demo-docx-normal.docx';
    $docx_high = 'https://orangerie.ae/samplefiles/demo-docx-high.docx';
    $docx_big = 'https://orangerie.ae/samplefiles/demo-docx-big.docx';
    $docx_large = 'https://orangerie.ae/samplefiles/demo-docx-large.docx';

    $doc_small = 'https://orangerie.ae/samplefiles/demo-doc-small.doc';
    $doc_normal = 'https://orangerie.ae/samplefiles/demo-doc-normal.doc';
    $doc_high = 'https://orangerie.ae/samplefiles/demo-doc-high.doc';
    $doc_big = 'https://orangerie.ae/samplefiles/demo-doc-big.doc';
    $doc_large = 'https://orangerie.ae/samplefiles/demo-doc-large.doc'; 

    $data = file_get_contents( $doc_high );
    echo base64_encode($data);
?>

期待 Base64 编码的文件内容,但 chrome 显示“此页面无法正常工作。orangerie.ae 未发送任何数据。ERR_EMPTY_RESPONSE”

标签: phpbase64

解决方案


我在cli和php内部服务器上尝试,都返回成功。

首先,你必须找到错误在哪里。是 file_get_contents 错误还是 base64_encode 错误或 echo content 错误。

你检查你的服务器超时配置,memory_limit。

祝你找到答案


推荐阅读