V
V
Vlad2015-09-01 14:38:06
PHP
Vlad, 2015-09-01 14:38:06

How to archive files in PHP?

Hello.
Can you please tell me how to archive the folder / files I need in PHP into a .zip archive?
It is desirable the fastest way so that 10 mb archiving occurs as quickly and imperceptibly as possible.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Vanin, 2015-09-01
@vanton

The fastest way is to use the command line on the server, for example:
There is also a solution by David Walsh that uses the ZipArchive php class, but php must support this class

S
Stalker_RED, 2015-09-01
@Stalker_RED

php.net/manual/ru/book.zip.php

P
Pavel Volintsev, 2015-09-01
@copist

If OOP is required, then you can do this based on the option that @vanton suggested

<?php
/**
 * @see http://php.net/manual/ru/class.ziparchive.php
 */
class MyZipArchive extends ZipArchive // унаследовал
{
   public function addFiles($files = array()) // расширил
   {
      // ... см. http://davidwalsh.name/create-zip-php 
   }
}

$zip = new MyZipArchive;
$zip->open($zipTmpAbsFilePath, \ZipArchive::OVERWRITE);
$zip->addFiles(array(
  'preload-images/1.jpg',
  'rod.jpg',
));

// ещё есть стандартные функции
  // $zip->addGlob('path/to/files/*.*');
  // $zip->addPattern('*.*', 'path/to/files/')

$zip->close();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question