php - 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”
解决方案
我在cli和php内部服务器上尝试,都返回成功。
首先,你必须找到错误在哪里。是 file_get_contents 错误还是 base64_encode 错误或 echo content 错误。
你检查你的服务器超时配置,memory_limit。
祝你找到答案
推荐阅读
- jquery - URL 中的问号未正确编码
- php - 函数 get_post 并返回 mysqli_real_escape_string - PHP
- git - Github.io 找不到工件:
- wordpress - 如何通过 IP 地址限制对 WordPress 管理员登录页面的访问,而不影响客户注销过程?
- java - 如何在 Spring Security antmatchers 中使用参数
- sql - 在 PostgreSQL 中为特定 ID 选择最大值
- django - 使用来自不同模型模板的 kwargs 在 Django 中创建 CreateView
- java - 如果出现任何类型的异常,重定向到错误控制器?
- vue.js - VueJS 2:如何按顺序加载静态 JS?
- highcharts - 在 jhipster 中使用 highcharts