duan7772 2017-05-17 09:08
浏览 195
已采纳

(PHP)解压缩并重命名CSV文件?

I want to download different feeds form some publishers. But the poor thing is, that they are first of all zipped as .gz and as second not in the right format. You can download one of the feeds and check it out. They do not have any filespec... So, I'm forced to add the .csv by myself..

My question now is, how can I unzip those files from the different urls? How I do rename them, I know. But how do I unzip them?

I already searched for it and found this one:

//This input should be from somewhere else, hard-coded in this example
$file_name = '2013-07-16.dump.gz';

// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $file_name); 

// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb'); 

// Keep repeating until the end of the input file
while (!gzeof($file)) {
    // Read buffer-size bytes
    // Both fwrite and gzread and binary-safe
    fwrite($out_file, gzread($file, $buffer_size));
}

// Files are done, close files
fclose($out_file);
gzclose($file);

But with those feeds it doesn't work... Here a two example files: file one | file two

Do you have an idea? - Would be very grateful! Greetings!

  • 写回答

1条回答 默认 最新

  • doubiankang2845 2017-05-17 10:52
    关注

    windows 10 + php7.1.4 it's work.

    The following code has the same effect.

    ob_start();
    readgzfile($file_name);
    file_put_contents($output_filename', ob_get_contents());
    ob_clean();
    

    Or you can try to use the gzip command to decompress, and then use the it. Program execution Functions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站