Dakusan's Domain Forum

Main Site Discussion => Posts => Topic started by: Dakusan on October 03, 2015, 03:57:31 pm

Title: Missing phar wrapper
Post by: Dakusan on October 03, 2015, 03:57:31 pm
Original post for Missing phar wrapper can be found at https://www.castledragmire.com/Posts/Missing_phar_wrapper.
Originally posted on: 10/03/15

Phar files are PHP’s way of distributing an entire PHP solution in a single package file. I recently had a problem on my Cygwin PHP server that said “Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP?”. I couldn’t find any solution for this online, so I played with it a bit.

The quick and dirty solution I came up with is to include the phar file like any normal PHP file, which sets your current working directory inside of the phar file. After that, you can include files inside the phar and then change your directory back to where you started. Here is the code I used:

if(preg_match('/^(?:win|cygwin)/i', PHP_OS))
{
   $CWD=getcwd();
   require_once('Scripts/PHPExcel.phar');
   require_once('PHPExcel/IOFactory.php');
   chdir($CWD);
}
else
   require_once('phar://Scripts/PHPExcel.phar/PHPExcel/IOFactory.php');