|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- include "header.php";
- connecte("ecomonde");
- $hash=md5($email);
- $path="./medias/".$hash;
-
- class HZip
- {
- /**
- * Add files and sub-directories in a folder to zip file.
- * @param string $folder
- * @param ZipArchive $zipFile
- * @param int $exclusiveLength Number of text to be exclusived from the file path.
- */
- private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
- $handle = opendir($folder);
- while (false !== $f = readdir($handle)) {
- if ($f != '.' && $f != '..') {
- $filePath = "$folder/$f";
- // Remove prefix from file path before add to zip.
- $localPath = substr($filePath, $exclusiveLength);
- if (is_file($filePath)) {
- $zipFile->addFile($filePath, $localPath);
- } elseif (is_dir($filePath)) {
- // Add sub-directory.
- $zipFile->addEmptyDir($localPath);
- self::folderToZip($filePath, $zipFile, $exclusiveLength);
- }
- }
- }
- closedir($handle);
- }
-
- /**
- * Zip a folder (include itself).
- * Usage:
- * HZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
- *
- * @param string $sourcePath Path of directory to be zip.
- * @param string $outZipPath Path of output zip file.
- */
- public static function zipDir($sourcePath, $outZipPath)
- {
- $pathInfo = pathInfo($sourcePath);
- $parentPath = $pathInfo['dirname'];
- $dirName = $pathInfo['basename'];
-
- $z = new ZipArchive();
- $z->open($outZipPath, ZIPARCHIVE::CREATE);
- $z->addEmptyDir($dirName);
- self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
- $z->close();
- }
- }
-
-
- if ($email) {
- exec("rm -rf {$path}.zip");
- HZip::zipDir($path, './medias/'.$hash.'.zip');
- header("location:./medias/c0f08ae603e364cb554fe71c9fc94ffd.zip");
- }
- else {
- header("location:index.php?msg=0");
- }
- ?>
|