اسکریپت باران
بزرگترین مرجع دانلود سورس و اسکریپت های برنامه نویسی
تابع زیر می تواند برای فشرده کردن (zip کردن) یک پوشه (Folder) و تمام پوشه ها و فایل های درون آن، به کار رود :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php // ساخت یک فایل زیپ از تمامی فایل های یک پوشه function Build_Zip_File_From_A_Complete_Folder($folder_to_zip_path, $destination_zip_file_path){ // Get real path for our folder $rootPath = realpath($folder_to_zip_path); // Initialize archive object $zip = new ZipArchive(); $zip->open($destination_zip_file_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // Skip directories (they would be added automatically) if (!$file->isDir()) { // Get real and relative path for current file $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($rootPath) + 1); // Add current file to archive $zip->addFile($filePath, $relativePath); } } // Zip archive will be created only after closing object $zip->close(); } ?> |
کانال تلگرامی اسکریپت باران
برای اطلاع از آپدیت های این سورس و سورس های دیگر اسکریپت باران، در کانال تلگرام ما عضو شویدبرنامه نویسی را معنایی دوباره بخشیم !