2011-09-06 2 views
5

tar 파일을 디렉토리에 압축을 풀려고하지만 어떻게 될지 모릅니다. tar 파일과 동일한 디렉토리로 추출 할 수 있지만 다른 폴더에는 추출 할 수 없습니다. (아무것도 추출되고 있지)tar 파일을 디렉토리로 압축 해제

$filename = "homedir.tar"; 
exec("tar xvf $filename"); 

는 다음를 시도했지만 작동하지 않습니다 :

exec("tar -C, homedir zxvf $filename"); 

업데이트 :

# Absolute paths 
$filepath = "/home/acc/public_html/test/test/homedir.tar"; 
$folderpath = "/home/acc/public_html/test/test/homedir"; 

# Check if folder exist 
if(!is_dir($folderpath)) { 
    die('Folder does not exist'); 
} 

# Check if folder is writable 
if(!is_writable($folderpath)) { 
    die('Folder is not writable'); 
} 

# Check if file exist 
if(!file_exists($filepath)) { 
    die('File does not exist'); 
} 

exec("tar -C $folderpath -zxvf $filepath"); 
: 이것은 내 파일의 내용이

입니다

오류는 없지만 압축을 풀지 않습니다.

+0

웹 서버에 pear tar가 설치되어 있습니까? – Mythli

+0

두 번째 매개 변수로 빈 배열을 전달한 다음 해당 배열의 내용을 검사 해보십시오. 무엇이 잘못되었는지에 대한 단서를 줄 수있는 모든 출력을 보여줍니다. 참조하십시오 : http://us3.php.net/manual/en/function.exec.php – gregghz

+0

나는 그것을 시도 빈 $ status = array(); exec ("tar -C $ folderpath -zxvf $ filepath", $ status); print_r ($ status); –

답변

3

에 -C에서 쉼표를 제거하고 zxvf 전에 대시를 추가

exec("tar -C $outdir -zxvf $infile"); 

아니면 끝에 -C 부분을 넣을 수 있습니다 그리고 당신은 zxvf 전에 대시 필요가 없습니다

exec("tar zxvf $infile -C $outdir"); 

그리고 확실하게 경로가 절대적인지 확인해야합니다.

+0

내 error_log에 가져 오기 : [06-Sep-2011 14:39:11] PHP 경고 : 모듈 'json'은 이미 Unknown in line 0에로드되었습니다. –