浏览代码

Fonctions fichiers (zip, suppression dossier)

master
Guillaume 4 年前
父节点
当前提交
8894a34a8f
共有 2 个文件被更改,包括 46 次插入0 次删除
  1. +7
    -0
      ShopBundle/Resources/views/backend/default/list.html.twig
  2. +39
    -0
      ShopBundle/Services/Utils.php

+ 7
- 0
ShopBundle/Resources/views/backend/default/list.html.twig 查看文件

@@ -141,6 +141,13 @@
</a>
{% endif %}

{% if _entity_config['list']['btn_download_purchase_order_archive'] is defined %}
<a class="float-right btn-sm btn-success action-confirm"
href="{{ path('easyadmin', { entity: 'Supplier', action: 'exportOrderPurchasesAsArchive' }) }}">
<i class="fa fa-download"></i> Télécharger tous les bons de commande
</a>
{% endif %}

{% if _entity_config['list']['edit_position'] is defined %}
<a class="float-right btn-sm btn-success action-sort"
href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}">

+ 39
- 0
ShopBundle/Services/Utils.php 查看文件

@@ -394,4 +394,43 @@ class Utils
}
return $reminders;
}

public function removeDir($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? $this->removeDir("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}

function folderToZip($folder, &$zipFile, $subfolder = null) {
if ($zipFile == null) {
// no resource given, exit
return false;
}
// we check if $folder has a slash at its end, if not, we append one
$tabFolder = str_split($folder) ;
$tabSubFolder = str_split($subfolder) ;
$folder .= end($tabFolder) == "/" ? "" : "/";
$subfolder .= end($tabSubFolder) == "/" ? "" : "/";
// we start by going through all files in $folder
$handle = opendir($folder);
while ($f = readdir($handle)) {
if ($f != "." && $f != "..") {
if (is_file($folder . $f)) {
// if we find a file, store it
// if we have a subfolder, store it there
if ($subfolder != null)
$zipFile->addFile($folder . $f, $subfolder . $f);
else
$zipFile->addFile($folder . $f);
} elseif (is_dir($folder . $f)) {
// if we find a folder, create a folder in the zip
$zipFile->addEmptyDir($f);
// and call the function again
folderToZip($folder . $f, $zipFile, $f);
}
}
}
}
}

正在加载...
取消
保存