Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FileComponent.php 2.8KB

pirms 3 gadiem
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Lc\SovBundle\Component;
  3. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  4. class FileComponent
  5. {
  6. protected ParameterBagInterface $parameterBag;
  7. public function __construct(ParameterBagInterface $parameterBag)
  8. {
  9. $this->parameterBag = $parameterBag;
  10. }
  11. /**
  12. * Retourne le chemin vers le dossier d'uploads de responsiveFilemanager
  13. *
  14. * @return string
  15. */
  16. public function getFileManagerFolder()
  17. {
  18. return $this->parameterBag->get('app.path.images');
  19. }
  20. // lcLiip
  21. public function liip($path, $thumb = 'tile', $default = 'default.jpg')
  22. {
  23. if (substr($path, 0, 1) === '/') $path = substr($path, 1);
  24. if ($path) {
  25. $fileManagerFolder = substr($this->getFileManagerFolder(), 1) ;
  26. if (strpos($path, $fileManagerFolder) === false) {
  27. $path = $fileManagerFolder . '/' . $path;
  28. }
  29. if (file_exists($path)) {
  30. return $this->liipCacheHelper->getBrowserPath($path, $thumb);
  31. }
  32. }
  33. return $this->liipCacheHelper->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb);
  34. }
  35. public function removeDir($dir)
  36. {
  37. $files = array_diff(scandir($dir), array('.', '..'));
  38. foreach ($files as $file) {
  39. (is_dir("$dir/$file")) ? $this->removeDir("$dir/$file") : unlink("$dir/$file");
  40. }
  41. return rmdir($dir);
  42. }
  43. function folderToZip($folder, &$zipFile, $subfolder = null)
  44. {
  45. if ($zipFile == null) {
  46. // no resource given, exit
  47. return false;
  48. }
  49. // we check if $folder has a slash at its end, if not, we append one
  50. $tabFolder = str_split($folder);
  51. $tabSubFolder = str_split($subfolder);
  52. $folder .= end($tabFolder) == "/" ? "" : "/";
  53. $subfolder .= end($tabSubFolder) == "/" ? "" : "/";
  54. // we start by going through all files in $folder
  55. $handle = opendir($folder);
  56. while ($f = readdir($handle)) {
  57. if ($f != "." && $f != "..") {
  58. if (is_file($folder . $f)) {
  59. // if we find a file, store it
  60. // if we have a subfolder, store it there
  61. if ($subfolder != null)
  62. $zipFile->addFile($folder . $f, $subfolder . $f);
  63. else
  64. $zipFile->addFile($folder . $f);
  65. } elseif (is_dir($folder . $f)) {
  66. // if we find a folder, create a folder in the zip
  67. $zipFile->addEmptyDir($f);
  68. // and call the function again
  69. folderToZip($folder . $f, $zipFile, $f);
  70. }
  71. }
  72. }
  73. }
  74. }