<?php
/*
*r10 Saitama
*/
# Klasördeki dosyaları bir dosyaya sıkıştırın
class Zip
{
/**
* Hedef klasörün içeriğini bir zip içine sıkıştırın (zip klasör dizinini içerir)
* @param $sourcePath *Klasör yolu örneği: /home/test
* @param $outZipPath *zip dosya adı (yol ile birlikte) Örnek: /home/zip_file/test.zip
* @return string
*/
public static function zipFolder($sourcePath, $outZipPath)
{
$parentPath = rtrim(substr($sourcePath, 0, strrpos($sourcePath, '/')),"/")."/";
$dirName = ltrim(substr($sourcePath, strrpos($sourcePath, '/')),"/");
$sourcePath=$parentPath.'/'.$dirName;//prevent bugs from being created by passing 'folder' folders
$z = new \ZipArchive();
$z->open($outZipPath, \ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
folderToZip($sourcePath, $z, strlen("$parentPath/"));
$z->close();
return $outZipPath;
}
public static function folderToZip($folder, &$zipFile, $exclusiveLength)
{
$handle = opendir($folder);
while (false !== $f = readdir($handle)) {
if ($f != '.' && $f != '..') {
$filePath = "$folder/$f";
// Zip'e eklemeden önce dosya yolundan ön eki kaldırın
$localPath = substr($filePath, $exclusiveLength);
if (is_file($filePath)) {
$zipFile->addFile($filePath, $localPath);
} elseif (is_dir($filePath)) {
// Alt klasör ekle
$zipFile->addEmptyDir($localPath);
self::folderToZip($filePath, $zipFile, $exclusiveLength);
}
}
}
closedir($handle);
}
}Not yinede test etmeniz önerilir
Php İle Tüm site dosyalarınızı Zipleyin
0
●174
- 30-06-2023, 22:39:25Tek bir php koduyla tüm sitenizi zipleyin
