I have been trying recently to open a zip archive, select a particular file within the archive, open it, and access its day to be displayed within a web page.
I have managed to open the zip archive and select the specified file, which is an XML file type.
However, I am finding it quite difficult to make the jump from working within the zip functions to the XML functions provided within PHP.
My goal is to create a dynamic webpage that will do the following: read all files within the directory (successfully accomplished), determine which are sub-directories, files, and display only a selected file type (successfully accomplished); and display specific data contained within the displayed files.
To provide more information on the project, the files located within the directory I'm working within are e-book files, of EPUB format, which is essentially a ZIP archive with a different extension. I wish to open the EPUB, locate "content.opf" and extract its contents for parsing into a user-friendly display.
I can access the file without accessing anything else. I can even access the data contained within as evidenced by the source code of the webpage, showing that the XML data has been loaded into the page as it appears in the original, compressed file. I can't however figure out how to make use of this data. I've been using various XML functions but none of them seem to accept the idea of opening a file located inside a zip archive.
I realize that this is a little more advanced than the usual "newbie" fare but I'm pulling information from google searches and cobbling it together so, I'm still very "newb-ish".
Has anyone attempted to do something similar to this?
Code (strictly for access of XML document) is as follows:
function zipopener()
{
$zip = zip_open('title.epub');
if ($zip)
{
while ($zip_entry = zip_read($zip))
{
if (zip_entry_name($zip_entry) == 'OEBPS/content.opf')
{
if (zip_entry_open($zip, $zip_entry))
{
echo "File Contents:<br/>";
$contents = zip_entry_read($zip_entry);
echo "$contents<br />";
echo "<br /><br />";
zip_entry_close($zip_entry);
}
echo "</p>";
}
}
}
}
if ($folder = opendir('.'))
{
zipopener();
closedir($folder);
}