php如何压缩txt文件怎么打开,PHP-压缩txt文件,同时保持文件扩展名

我想在PHP中压缩.txt文件,同时保持文件扩展名.当我解压缩.gz文件时,.gz文件中的扩展名(.txt)被删除. (test.txt变成-> test)

这是我的将test.txt压缩为.gz文件的PHP代码的示例:

// Name of the file we are compressing

$file = "test.txt";

// Name of the gz file we are creating

$gzfile = "test.gz";

// Open the gz file (w9 is the highest compression)

$fp = gzopen ($gzfile, 'w9');

// Compress the file

gzwrite ($fp, file_get_contents($file));

// Close the gz file and we are done

gzclose($fp);

?>

有人知道我在做什么错吗?还是因为gzip限制?

解决方法:

通常,在解压缩时,gzip不会在gzip标头中使用名称,而且您也不会在标头中存储名称.它只是从文件名中删除.gz.您需要将文件命名为test.txt.gz才能将其解压缩为test.txt.

标签:compression,gzip,gz,php

来源: https://codeday.me/bug/20191030/1971302.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值