简体   繁体   English

Phar 存档中的 Static 内容

[英]Static content inside phar archive

I was just wondering if it is legal to add static content to phar archives (images, javascript or html files).我只是想知道将 static 内容添加到 phar 档案(图像,javascript 或 html 文件)是否合法。 And if so, how do I get them out to serve to a client?如果是这样,我如何让他们为客户服务?

The only example I've seen so far was:到目前为止,我看到的唯一例子是:

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

but I guess this is not a way to go.但我想这不是 go 的方法。

UPATE: Just in case someone will be trying to do the same. UPATE:以防万一有人试图做同样的事情。 This piece of code set as a stub of a phar archive worked for me:这段代码集作为 phar 存档的存根对我有用:

<?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 do stuff like setting header mime type and serving the static file content with readfile() manually. All static content inside the phar archive still passes through the php interpreter, but at least there is no need do stuff like setting header mime type and serving the static file content with readfile() manually. Those functions in the phar stub make it look transparent. phar 存根中的这些函数使其看起来透明。

but I guess this is not a way to go.但我想这不是 go 的方法。

Because the only thing that can look inside phars is PHP, having PHP extract the contents and echo the result is pretty much the only way to go.因为唯一可以查看 phars 内部的是 PHP,所以让 PHP 提取内容并回显结果几乎是 go 的唯一方法。

You might find the PHP manual page on the PHAR extension to be useful, and the webPhar method to be particularly enlightening.您可能会发现PHAR 扩展上的 PHP 手册页很有用,并且webPhar方法特别有启发性。 interceptFileFuncs could also be handy. interceptFileFuncs也很方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM