OK, There could also still be other problems, but you took away too much ./
By way of explanation, you don't really have to extract anything, but if you do, the path must be correct, and the path to the archive must be correct in any case. It is only the path inside the archive used by locateName that must reflect only the actual structure of the archive and not use the ./ or any local folders. So this should work assuming the pptx file is in the Reports folder off of the current working folder:
PHP Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// the string variable that will hold the file content
$file_content = "";
// open file
$file_path = './Reports/report.pptx'; // must be a valid pptx file with path relative to this script's working folder
$zip = new ZipArchive;
$res = $zip->open($file_path);
if ($res === TRUE) {
$zip->extractTo('./Reports/'); // not required, but if used, must be a valid local path, only needed if you want to have the files extracted
echo 'done<br>'; // this means we successfully opened the zip for processing
// loop through all slide#.xml files
$slide = 1;
while ( ($index = $zip -> locateName("ppt/slides/slide" . $slide . ".xml")) !== false ){ // must represent the internal structure of the archive - no local paths allowed
$data = $zip -> getFromIndex($index);
$xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
$file_content .= strip_tags($xml -> saveXML());
$slide++;
}
$zip->close();
} else {
echo 'failed'; // this means we failed to open any archive
}
echo $file_content;
?>
Bookmarks