2010-07-20 3 views

답변

2

Download the Unzip library 및 포함하거나 autoloadunzip 라이브러리

$this->load->library('unzip'); 
+0

링크가 죽었어. 내가 할 수 있으면이 링크를 찾아 보자. – fedmich

3

Zlib Compression 확장에 의해 구현 된 기능을 사용합니다.

이 조각은 확장에서 제공하는 기능 중 일부를 사용하는 방법을 보여줍니다

// open file for reading 
$zp = gzopen($filename, "r"); 

// read 3 char 
echo gzread($zp, 3); 

// output until end of the file and close it. 
gzpassthru($zp); 
gzclose($zp); 
36

PHP 자체는 GZIP 파일 처리를위한 기능이 있습니다.

압축되지 않은 새 파일을 만들려면 다음과 같이됩니다.

참고 : 대상 파일이 먼저 있는지, 입력 파일을 삭제하지 않았는지 또는 오류 검사를 수행하는지는 확인하지 않습니다. 프로덕션 코드에서 이것을 사용하기 전에 수정해야합니다.

// 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); 

참고 :이 gzip을 다루고있다. 타르는 다루지 않습니다.

+1

나는이 코드를 사용했고 완벽했다. gz 파일 내부의 폴더와 어떻게 작동하는지 묻는 방법과 추출 된 파일의 출력 폴더를 보여주는 방법. –

+1

@RealMan gzip은 단일 파일 만 지원합니다. 여러 파일의 경우 .tar.gz가 필요합니다. PHP가 tar를 지원하는지 여부는 잘 모르겠습니다. – Powerlord

3

당신이 시스템에 액세스 할 수()가있는 경우 :

system("gunzip file.sql.gz"); 
+0

작동해야하지만 대부분의 시간 동안 시스템()이 보안상의 이유로 비활성화됩니다. – fedmich

관련 문제