2017-07-09 100 views
0

這是我的代碼解壓縮文件,它正在工作。解壓縮後如何獲取解壓縮文件夾名稱。像zip文件名是'demo65856.zip',解壓文件夾名是'demo'。 感謝解壓後獲取文件夾名稱的名稱

if(isset($_POST['submit'])){ 

WP_Filesystem(); 
$destination = wp_upload_dir(); 
$normal_path = $path_array; 
$filename = $result->theme_file_name; 
$link_filename = substr($filename, 0, -4); 
$destination_path = $destination['basedir'].'/theme/'; 
$demo_link = $destination['baseurl'].'/theme/'.$link_filename; 
$unzipfile = unzip_file($destination_path.$filename, $destination_path); 

    if ($unzipfile) { 
    echo '<h3> <a href="'.$demo_link.'">demo link has created</a></h3>'; 
    } else { 
     echo 'There was an error unzipping the file.';  
    } 
} 

回答

0

從手冊,使用ZipArchive ...

<?php 
$zip = new ZipArchive; 
if ($zip->open($filename)) 
{ 
    for($i = 0; $i < $zip->numFiles; $i++) 
    { 
      echo 'Filename: ' . $zip->getNameIndex($i) . '<br />'; 
    } 
} 
else 
{ 
    echo 'Error reading zip-archive!'; 
} 
?> 

所以這取決於有多少文件是在基本級別,你可能只是有一個基本目錄或文件的列表。你需要嘗試一下,看看你得到了什麼。

+0

可以在我的代碼中實現您的代碼? – fiyan

相關問題