2010-05-10 5 views
1

내 CMS에 대한 쉬운 설치 프로그램 \ setupper와 같은 것을 만들었습니다. 사용자가 내 CMS로 .zip을 다운로드하고 PHP 서버의 일부 폴더에 압축을 풀면 파일 - install.php와 Zip 폴더 인 - Contents.zip이 표시됩니다. Contents.zip zip 파일에서 파일을 추출하려면 PHP 함수가 필요합니다. 그 파일을 삭제하는 것보다. (가능한 경우 폴더 압축 해제 직후 파일/폴더에 다른 권한을 부여하고 싶습니다.)폴더의 압축을 해제하고 압축 된 원본을 삭제하는 방법은 무엇입니까?

어떻게 이런 일을 할 수 있습니까?

답변

2

당신은 PHP ZipArchive library을 사용할 수 있습니다.

code example from the documentation 유용 할 것입니다.

<?php 

$zip = new ZipArchive(); 
$filename = "./test112.zip"; 

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { 
    exit("cannot open <$filename>\n"); 
} 

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n"); 
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n"); 
$zip->addFile($thisdir . "/too.php","/testfromfile.php"); 
echo "numfiles: " . $zip->numFiles . "\n"; 
echo "status:" . $zip->status . "\n"; 
$zip->close(); 
?> 

파일 권한을 변경하는 경우, 예를 들어 PHP builtin function chmod.

사용할 수 있습니다

chmod("/somedir/somefile", 0600); 

사용할 수있는 파일을 삭제하려면, 예를 들어 php builtin unlink

,

unlink('test.html'); 
unlink('testdir'); 

나는 PHP 공식 문서를 살펴보기 위해 yuo를 강력히 추천한다.

+0

공식 PHP 5.2 defalt apache php의 "PHP ZipArchive library"부분입니까? – Rella

+0

그리고 그 zip 파일을 어디에서 삭제합니까? – Rella

+0

@Ole 예, ZipArchive는 공식 배포판을 제공합니다. 그러나 그것은 http://www.zlib.net/ – phoenix24

관련 문제