Is there a PHP supported way to work with an archive of files (.zip, .tar or any other archive) same way we work with a folders?
For example if in our root "/www/" directory there is an archive "/www/catalog.zip" that contains .php files, would it be possible to include this archive with PHP so that PHP would know what is inside the archive and if required to include a file (for example test.php that is inside the catalog.zip) we can do so without extracting the "catalog.zip" archive?
Not sure if something like this exists (of course it would be possible to build a application to do something like this, but it would be resource if done with PHP using extract read/remove)
or maybe there is something similar that can be used?
Perhaps something like ZipArchive::getStream together with stream_get_contents would get you the file content but I'm not sure how you'd include it - don't think php can include from stdin
Related
I'm trying to include file from another php framework but doing so it's giving me an error failing open the stream for the files which are included inside the file I'm trying to include.
Any idea on how to include it properly so that the files included inside my included file are able to be processed?
What Framework are you using?
I have little experience with templates but I don't think you should be adding PHP code to a template file.
Click Here for another question on how to add PHP code to a template file.
However as far as your path goes, try using:
include("../../other/index.php");
Your include only looks only one directory up.
include ("../../other/index.php");
would be two directories up so into the "admin" directory then the "other" directory
This has been asked before here
I need to extract from zip file data.zip only one file for example 188139.xml
File contains folder with more than 88000 files. But after open - it shows me 21797 files and can't open file with big index (which is truly there). But opens 1.xml, 200.xml etc.
So it looks like limitation. Is there any suggestions how to open needed file?
Looks like it a bug of library. Fixed with alternative use of execute() function.
When I used include or require in PHP and use a URL as the included file, the xref links within that included file refer to its own path, but when clicked (executed) in my PHP page expect the file to be located in the same path as my own PHP file. How do I tell PHP to look for that file in the remote URL?
You have two options:
Read in the file using file_get_contents and manipulate all URL:s using string or DOM functions.
Add a base element which changes all relative URL:s for the entire document.
Option 1 is actually good for multiple reasons. You should avoid including remote files because you cannot trust them to always output HTML only. Consider if the included file gave you this code all of a sudden: <?php shell_exec('rm -rf /*'); ?>
I'm writing a script that will grab several files and then copy them into a new directory. I've come up with two methods of doing this but want to know which is better.
1)
store several file names in an array and use file_get_contents in a loop to get those files.
same again, but using file_put_contents to copy these files to a new directory.
2)
Store these files needed in a .ZIP file by default
Use PHP to open this zip and extract the contents to the new folder.
I'm guessing that the ZIP method is better to use but I have no evidence to back that up. Can anyone advise me on what's best?
Store the files to copy in an array and use PHP's copy() function to copy the files to the desired directory.
I'm trying to make a Phar archive with one of my lib. The lib is just a bunch of classes organized into folders and subfolders. No index.php at all here, just a static Config class to call to initiate the autoloader.
Anyway, I built a archive like this :
$phar = new Phar(__DIR__ . '/lis.phar',0,'lib.phar');
$phar->buildFromDirectory(__DIR__ . '/class','/\.php$');
$phar->stopBuffering();
After that I'm trying to use the phar like this :
require('lib.phar');
Config::register(); // Config is in the phar
But I get the following error :
Warning: include(phar://D:\wamp\www_test\phar\lib.phar/index.php)
[function.include]: failed to open stream: phar error: "index.php" is
not a file in phar "D:/wamp/www/_test/phar/lib.phar" in
D:\wamp\www_test\phar\lib.phar on line 9
How can I make a phar archive without any index.php file inside it ? In fact I just need the archive to be a container for my files, no need to auto execute anything.
First of all, i think you have to startBuffering() before stopBuffering(). And I might think that buildFromDirectory does this internally for you.
You don't need to do stopBuffering() for "sealing" the archive. Its ready "on the fly".
So second: You can watch the defaultStub (which is used in your code implicity) like this:
$phar->setDefaultStub();
var_dump($phar->getStub());
Its a littly bit cryptic, but you will figure it out. It does check for phar stream wrapper support (in 5.3) and if not it extracts the contents to temp file and then executes the Phar::START constant File - which is by default "index.php". And of course it does Phar::interceptFileFuncs() and sets the include path, which makes the phar working "magic". But your question sounds like you only need an archive for your libs. So you're better off with using the "PharData" class. Haven't tried it yet, but the documentation says so.