如何使用php提取或解压缩gzip文件?
压缩文件可以使用PHP的gzread函数解压缩或解压缩。以下是相同的代码示例-
示例
$file_name = name_of/.dump.gz';
$buffer_size = 4096; // The number of bytes that needs to be read at a specific time, 4KB here
$out_file_name = str_replace('.gz', '', $file_name);
$file = gzopen($file_name, 'rb'); //Opening the file in binary mode
$out_file = fopen($out_file_name, 'wb');
//一直重复直到输入文件结束
while (!gzeof($file)) {
fwrite($out_file, gzread($file, $buffer_size)); //Read buffer-size bytes.
}
fclose($out_file); //Close the files once they are done with
gzclose($file);输出结果
这将产生以下输出-
The uncompressed data which is extracted by unzipping the zipped file.
压缩文件的路径存储在名为“file_name”的变量中。一次需要读取的字节数是固定的,并分配给名为“buffer_size”的变量。输出文件没有扩展名.gz,因此输出文件名存储在名为“out_file_name”的变量中。
从提取的zip文件读取后,“out_file_name”以写二进制模式打开,以将内容附加到其中。在读取模式下打开“file_name”,并使用“gzread”功能读取内容,并将提取的这些内容写入“out_file”。运行while循环以确保读取内容直到文件末尾。
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练