Static content inside phar archive

I'm just wondering if it was legal to add static content to phar archives (images, javascript or html files). And if so, how do I get them to serve the customer?

The only example I've seen so far:

<?php header('Content-type: image/jpeg'); echo file_get_contents('phar:///fullpath/to/coollibrary.phar/images/wow.jpg'); ?> 

but I think this is not an option.

UPATE: Just in case, someone will try to do the same. This part of the code, installed as a stub of the phar archive, worked for me:

 <?php Phar::interceptFileFuncs(); Phar::mungServer(array('REQUEST_URI')); Phar::webPhar(); __HALT_COMPILER(); ?> 

All static content inside the phar archive still passes through the php interpreter, but at least there is no need to do such things as setting the mime type of the header and serving the static contents of the file with readfile () manually. These functions in the phar stub look transparent.

+7
source share
1 answer

but I think this is not an option.

Since the only thing that can look inside phars is PHP, with PHP extracting content and an echo result, pretty much the only way to go.

You can find the PHP help page on the PHAR extension , and the webPhar method to be especially useful. interceptFileFuncs may also be convenient.

+7
source

All Articles