phpphar

prevent PHAR from creating directories


I'm using PharData to compress a [single] specific file (/var/www/html/folder/specificfile.ext) which is not a jpg, jpeg, png, or gif. The issue is in the tar archive there's folders created with the path above. Is there a way to create the tar with no folders with PharData?

if ( !in_array($attachment, array('jpg', 'jpeg', 'png', 'gif'), true ) ) { 

try
{
    $a = new PharData($imgzip);

    $a->addFile($img);

} 
catch (Exception $e) 
{
    echo "Exception : " . $e;
}

}

Solution

  • When calling addFile, manually calculate the 2nd argument:

    $pharData->addFile($filename, basename($filename));