Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

export_data.php 1.8 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. include "header.php";
  3. connecte("ecomonde");
  4. $hash=md5($email);
  5. $path="./medias/".$hash;
  6. class HZip
  7. {
  8. /**
  9. * Add files and sub-directories in a folder to zip file.
  10. * @param string $folder
  11. * @param ZipArchive $zipFile
  12. * @param int $exclusiveLength Number of text to be exclusived from the file path.
  13. */
  14. private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
  15. $handle = opendir($folder);
  16. while (false !== $f = readdir($handle)) {
  17. if ($f != '.' && $f != '..') {
  18. $filePath = "$folder/$f";
  19. // Remove prefix from file path before add to zip.
  20. $localPath = substr($filePath, $exclusiveLength);
  21. if (is_file($filePath)) {
  22. $zipFile->addFile($filePath, $localPath);
  23. } elseif (is_dir($filePath)) {
  24. // Add sub-directory.
  25. $zipFile->addEmptyDir($localPath);
  26. self::folderToZip($filePath, $zipFile, $exclusiveLength);
  27. }
  28. }
  29. }
  30. closedir($handle);
  31. }
  32. /**
  33. * Zip a folder (include itself).
  34. * Usage:
  35. * HZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
  36. *
  37. * @param string $sourcePath Path of directory to be zip.
  38. * @param string $outZipPath Path of output zip file.
  39. */
  40. public static function zipDir($sourcePath, $outZipPath)
  41. {
  42. $pathInfo = pathInfo($sourcePath);
  43. $parentPath = $pathInfo['dirname'];
  44. $dirName = $pathInfo['basename'];
  45. $z = new ZipArchive();
  46. $z->open($outZipPath, ZIPARCHIVE::CREATE);
  47. $z->addEmptyDir($dirName);
  48. self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
  49. $z->close();
  50. }
  51. }
  52. if ($email) {
  53. exec("rm -rf {$path}.zip");
  54. HZip::zipDir($path, './medias/'.$hash.'.zip');
  55. header("location:./medias/c0f08ae603e364cb554fe71c9fc94ffd.zip");
  56. }
  57. else {
  58. header("location:index.php?msg=0");
  59. }
  60. ?>