Using phar to create tar.gz archive returns a strange error, the following is the error message:
exception 'BadMethodCallException' with message 'Unable to add newly converted phar "c:/www/dimg/uploads/7e6d3a5e39e43d1351e7069517f11250.tar.gz" to the list of phars, a phar with that name already exists' in c:\www\dimg\upload.php:163 Stack trace:
0 c:\www\dimg\upload.php(163): PharData->compress(4096)
1 {main}
The snippet to produce Phar archives am using:
$dir_id = md5(microtime() . $_SERVER['REMOTE_ADDR']);
$upload_dir = 'uploads/' . $dir_id;
mkdir($upload_dir, 777);
try {
$a = new PharData($upload_dir . '.tar.gz');
$a->buildFromDirectory($upload_dir);
$a->compress(Phar::GZ);
} catch (Exception $e) {
$error = true;
$err_msg .= '<li>Exception : ' . $e . '</li>';
}
I tried to empty uploads directory but the same error is produced each time.
Instead of using
$a = new PharData($upload_dir . '.tar.gz');
Use:
$a = new PharData($upload_dir . '.tar');
Actually compress generates two .tar and then tar.gz. Since you have specified .tar.gz as the initial output, it cannot overwrite it with the same file type.
I believe the problem is that you are trying to build the directory that the tar.gz is being sent to. In other words, you are telling it to build to a particular directory, and then telling it to build that directory.
All you should need to do is build the tar.gz in another directory than the one you are trying to compress.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With