【问题标题】:Get the name of folder name after unzip解压后获取文件夹名称
【发布时间】:2017-12-13 01:50:35
【问题描述】:

这是我的代码解压缩文件,它正在工作。解压后如何获取解压文件夹名称。像 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.';       
   } 
}

【问题讨论】:

    标签: php wordpress unzip


    【解决方案1】:

    从手册中,使用 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!'; 
    } 
    ?> 
    

    所以这取决于基本级别的文件数量,您可能只有一个基本目录或文件列表。你需要尝试一下,看看你会得到什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多