php base64转换成$_files,将excel base64转换为可下载文件PHP

每个人,即时运行在一些问题,现在,看看我无法控制的服务器或任何东西的内部情况,现在我不能使用base64编码的文件直接通过网站,因为当服务器提供内容的浏览器它有一个字符的限制对于这些任务,它会直接影响base64编码文件导致这些字符串的长度,所以我为一个系统创建了一个php脚本,它将已经存在的base64 pdf文件作为可下载文件提供给客户端,它的工作方式如下所示:

$reg = File::find($args->string('id')); //querying the file from database

$filename = $reg->filename; //the original file name

$base64 = $reg->file; //the base64 encoded file

$meta_type = explode(',', $base64) [0]; //getting the meta type of the file

$meta_type = str_replace('data:', '', $meta_type);

$meta_type = str_replace(';base64', '', $meta_type);

$file = explode(',', $base64) [1];

$file = base64_decode($base64); //decoding the base64 string

header('Content-Description: File Transfer');

header('Content-Type: ' . $meta_type);

header('Content-Disposition: attachment; filename="' . $filename . '"');

header('Expires: 0');

header('Cache-Control: must-revalidate');

header('Pragma: public');

header('Content-Length: ' . (strlen($file)));

echo $file;这工作得很好,当我使用PDF文件,但当我尝试使用它的一些'xlsx'文件似乎工作,它下载文件,文件大小和所有似乎匹配的原始,但excel无法打开文件,做任何人有一个想法,我即时失踪? :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值