D
D
Denis Kovalchuk2017-05-21 14:51:22
PHP
Denis Kovalchuk, 2017-05-21 14:51:22

How to add files with Cyrillic names to tar using Phar?

I need to pack a lot of jpg files with Cyrillic file names on the server into one file for upload.
If you do this:

$a = new PharData('/www/test/my.tar');
$a->addFile('/www/test/привет.jpg', "привет.jpg");

then php complains like this:
[BadMethodCallException] 
Entry привет.jpg does not exist and cannot be created: phar error: invalid path "привет.jpg" contains illegal character (0)
/www/test/tar.php:11
#0: PharData->addFile(string, string)
  /www/test/tar.php:11

And if you do this:
$a = new PharData('/www/test/my.tar');
$a->addFile('/www/test/привет.jpg', iconv('UTF-8', 'windows-1251', "привет.jpg"));

then it curses like this:
#0: PharData->addFile(string, string)
  /www/test/tar.php:13

If phar is not friendly with Cyrillic at all, then how else can you pack files into one archive without compression?
ZipArchive() is not suitable because even though it is fine with Cyrillic, it is bad with the lack of compression.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-05-21
@denisator

Everything is fine with ZipArchive with compression without compression
php.net/manual/en/ziparchive.setcompressionname.php
php.net/manual/en/zip.constants.php
CM_STORE
As for PHAR

$p =  new PharData('data.tar');
$p->addFile(__DIR__ . '/../app/кирилический файл.php', 'app/кирилический2.php');

Then everything works if the file __DIR__ . '/../app/cyrillic file.php' exists

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question