Strange error message with Phar
Using phar
to create an archive tar.gz
returns a strange error, the following error message:
"BadMethodCallException" with the message "Cannot add new converted phar" c: /www/dimg/uploads/7e6d3a5e39e43d1351e7069517f11250.tar.gz "to the list of phars, a phar with the same 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 for creating Phar archives uses:
$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 clear the downloads directory, but the same error occurs every time.
source to share
I believe the problem is that you are trying to create the directory that is sent to tar.gz
. In other words, you tell him to create a specific directory and then tell him that he is creating that directory.
All you have to do is build tar.gz
in a different directory than the one you are trying to compress.
source to share