├── .gitignore ├── backup └── .gitkeep ├── test.php ├── test_folder ├── test.html └── test │ └── test.html ├── CONTRIBUTING.md ├── README.md ├── LICENSE ├── ZipMaster.php └── CODE_OF_CONDUCT.md /.gitignore: -------------------------------------------------------------------------------- 1 | backup/* -------------------------------------------------------------------------------- /backup/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | archive(); -------------------------------------------------------------------------------- /test_folder/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test 6 | 7 | 8 |

Test

9 | 10 | -------------------------------------------------------------------------------- /test_folder/test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test 6 | 7 | 8 |

Test

9 | 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contribution are always **welcome and recommended**! Here is how: 2 | 3 | - Fork the repository ([here is the guide](https://help.github.com/articles/fork-a-repo/)). 4 | - Clone to your machine ```git clone https://github.com/YOUR_USERNAME/zipMaster.git``` 5 | - Make your changes 6 | - Create a pull request 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZipMaster 2 | Create zips with php. You can create zip with folders or files. 3 | 4 | We don't have to think about the folders anymore. 5 | 6 | ## Test Usage 7 | ```php 8 | archive(); 14 | ``` 15 | 16 | ### License 17 | ZipMaster is an open source project by [Erhan Kılıç](http://erhankilic.org) that is licensed under [MIT](http://opensource.org/licenses/MIT). 18 | 19 | ### Contribution 20 | Contribution are always **welcome and recommended**! Here is how: 21 | 22 | - Fork the repository ([here is the guide](https://help.github.com/articles/fork-a-repo/)). 23 | - Clone to your machine ```git clone https://github.com/YOUR_USERNAME/zipMaster.git``` 24 | - Make your changes 25 | - Create a pull request 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Erhan Kılıç 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ZipMaster.php: -------------------------------------------------------------------------------- 1 | https://github.com/erhankilic/ZipMaster 8 | * @version 1.0 9 | * @access public 10 | * @param $zip 11 | * @param $folder 12 | * @param $excludes 13 | */ 14 | class ZipMaster 15 | { 16 | private $zip; 17 | private $folder; 18 | private $excludes = []; 19 | 20 | /** 21 | * ZipMaster constructor. 22 | * @param string $output 23 | * @param string $folder 24 | * @param array $excludes 25 | * @param bool $replace 26 | * @throws \Exception 27 | */ 28 | public function __construct(string $output, string $folder, array $excludes = [], bool $replace = true) 29 | { 30 | if (empty($output) || empty($folder)) { 31 | throw new \Exception('Output and folder can not be empty string!'); 32 | } 33 | $this->folder = $folder; 34 | $this->excludes = $excludes; 35 | $this->zip = new \ZipArchive; 36 | try { 37 | // Replace previously created archive instead of updating it 38 | if ($replace && file_exists($output)) { 39 | unlink($output); 40 | } 41 | 42 | $this->zip->open($output, \ZipArchive::CREATE); 43 | } catch (\Exception $e) { 44 | throw new \Exception($e->getMessage()); 45 | } 46 | } 47 | 48 | /** 49 | * Opens the folder and reads all files and directories under the folder. 50 | * If there is directory, it calls itself again. 51 | * 52 | * @param string $folder 53 | * @param string|null $dir 54 | * @access private 55 | */ 56 | private function archiveFolder(string $folder, $dir = null) 57 | { 58 | if ($handle = opendir($folder)) { 59 | // Read all files and directories 60 | while (false !== ($entry = readdir($handle))) { 61 | // If file or directory isn't in excludes 62 | if ($entry != "." && $entry != ".." && !in_array($entry, $this->excludes)) { 63 | if (is_dir($folder . '/' . $entry)) { 64 | // If it's directory, call archiveFolder function again 65 | $this->archiveFolder($folder . '/' . $entry, $dir . '/' . $entry); 66 | } else { 67 | // Add all files inside the directory 68 | $this->zip->addFile($folder . '/' . $entry, $dir . '/' . $entry); 69 | } 70 | } 71 | } 72 | closedir($handle); 73 | } 74 | } 75 | 76 | /** 77 | * Archive the folder 78 | * 79 | * @param string|null $rootDirName 80 | * @access public 81 | */ 82 | public function archive($rootDirName = null) 83 | { 84 | $this->archiveFolder($this->folder, $rootDirName); 85 | $this->zip->close(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at erhan_kilic@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | --------------------------------------------------------------------------------