I read the topic "file archiver" here. I wondered whether it was possible to pack a lot of files into one file by encoding with a special algorithm. Compression percentage is not important. That is, it is not necessary to compress. The task is to push many files and folders into one file. How to do this with PHP?

Also need to unzip back. It is necessary to install, say self-written CMS.

  • Implementing ar or tar utilities in php? - alexlz
  • Not necessary. It is enough that all the files are in the same file. The algorithm is not important, the result is important. For example, when you send attachments by mail, the files are pushed into one “file” with delimiters and sent. Next, the client part pulls the attachment out of the letter. Something like that. - Yoharny Babay
  • Run ar by system ()? - alexlz
  • Most often in the hosting this is not possible. - Yoharny Babay
  • When sending a letter with attachments, they are already "shoving into one file with delimiters", see RFC-1521. And the client part "pulls out files from the letter." Of course, you can come up with your own version, even if it's self-made, even if you already have tar implementations in PHP (there are plenty of them, it's hard to find). It only remains to write your RFC and wait for everyone to follow it :) - user6550

2 answers 2

http://www.php.net/manual/ru/book.phar.php ? supports gzip compression, works quickly, efficiently and transparently.

    The simplest algorithm just born:

    заголовок { сигнатура (N байт, для верности) длина имени (1 или 2 байта) имя файла (с путём, длина_имени байт) атрибуты (M байт, зависит от целей) длина файла (4 или ? байт) } тело_файла 

    And according to this scheme, we draw files to the output stream one by one. Optionally, add the header CRC32, header length, encoding / packaging method, ctime / mtime, ... - until the next zip, arj, tar, gzip, bzip, rar etc is born :-)