Added document root when creating zip

Thanks to paravibe on Drupal.org for contributing.
pull/28/head
Frode Petterson 2016-09-23 10:31:55 +02:00
parent 5f38e2b7f8
commit 263a987eeb
1 changed files with 4 additions and 0 deletions

View File

@ -1574,11 +1574,15 @@ Class H5PExport {
$zip = new ZipArchive(); $zip = new ZipArchive();
$zip->open($tmpFile, ZipArchive::CREATE | ZipArchive::OVERWRITE); $zip->open($tmpFile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Some system needs the root prefix for ZipArchive's addFile()
$rootPrefix = (empty($_SERVER['DOCUMENT_ROOT']) ? '' : $_SERVER['DOCUMENT_ROOT'] . '/');
// Add all the files from the tmp dir. // Add all the files from the tmp dir.
foreach ($files as $file) { foreach ($files as $file) {
// Please note that the zip format has no concept of folders, we must // Please note that the zip format has no concept of folders, we must
// use forward slashes to separate our directories. // use forward slashes to separate our directories.
$zip->addFile($file->absolutePath, $file->relativePath); $zip->addFile($file->absolutePath, $file->relativePath);
$zip->addFile($rootPrefix . $file->absolutePath, $file->relativePath);
} }
// Close zip and remove tmp dir // Close zip and remove tmp dir