2014-07-23 32 views
1

我使用$zip->extractTo()來提取我的zip文件,這將創建一個包含所有文件的新文件夾,我只是想知道是否有離開我可以提取一個文件時間,並讓他們在根文件夾中,而不是爲我創建一個文件夾?一次提取zip文件一個文件

$zip = new ZipArchive(); 
if ($zip->open($path) === true) { 
    $zip->extractTo('../images/galleries/' . $galleryName); 
    $zip->close(); 
} 

回答

0

可以使用getFromNamegetFromIndex方法來提取單個文件的內容,然後寫入磁盤。例如:

$zip = new ZipArchive; 
$zip_filepath = '/path/to/zip/file'; 
$target_filepath = 'path/to/file/inside/zip'; 
$dest_filepath = '/path/to/extracted/file'; 

if ($zip->open($zip_filepath) === TRUE) { 
    file_put_contents($dest_filepath , $zip->getFromName($target_filepath)); 
    $zip->close(); 
}