从字符串

时间:2017-09-07 07:22:34

标签: php

我得到了一个像这样的字符串列表:

  • /my/path/to/file.txt
  • /another/path/to/another/file.jpg

现在我想使用https://github.com/Ne-Lexa/php-zip#Documentation-Open-Zip-Archive将文件添加到Zip存档。

好吧 - 这个库不会自动在zip中创建文件夹,所以我需要检查:

  • /my/path/to/file.txt的路径是什么? ( - > /my/path/to
  • 路径中是否存在路径?
  • 如果不是:创建它
  • 将文件添加到zip

目前我通过

解决了这个问题
private function archiveFile( $file )
{
    $path = pathinfo($path);
    $path = $path['dirname'];

    if(!isset($this->zip[$path])){
        $this->zip->addDirRecursive($path);
    }

    $this->zip->addFile( $file, $path );

    return true;
}

当我使用大量文件执行此操作时,我需要一个非常快速的方法来存档它。

0 个答案:

没有答案