国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

linux - php 解壓縮.gz檔案格式的方法。
黃舟
黃舟 2017-06-08 11:01:56
0
2
1088
  1. 現(xiàn)在專案我透過url取得到了.gz的檔案

  2. #我要處理解壓處理壓縮檔案的內(nèi)容

  3. 現(xiàn)在知道一種辦法,是php呼叫l(wèi)inux的系統(tǒng)指令tar去解壓縮,然後處理資料

#我想問有沒有處理過的朋友,可以php函數(shù)處理的!

第一次接觸,求指教!

黃舟
黃舟

人生最曼妙的風(fēng)景,竟是內(nèi)心的淡定與從容!

全部回覆(2)
僅有的幸福

php原聲支持,以下來自SO

// This input should be from somewhere else, hard-coded in this example
$file_name = 'file.txt.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);
學(xué)習(xí)ing

一般php安裝都自備tar的擴充包,這是我專案中tar的解壓縮函數(shù),僅供參考

function get_files_name_in_tar($file) {
    require_once 'Archive/Tar.php';
    $ext = get_file_extension($file);
    $tar_handle = null;
    if ($ext === "bz2") {
        $tar_handle = new Archive_Tar($file, "bz2");
    } else if ($ext === "gz") {
        $tar_handle = new Archive_Tar($file, "gz");
    } else if ($ext === "tar") {
        $tar_handle = new Archive_Tar($file);
    } else {
        return false;
    }    
    if (!$tar_handle) {
        return false;
    }    
    $entry_names = $tar_handle->listContent();

    return array_column($entry_names, 'filename');
}

另外可參考:PHP tar格式解壓縮的三種方式
還可以透過linux,在php中呼叫linux指令tar

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板