From 263a987eeb515195460a20a2560862a42fa8fea5 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 23 Sep 2016 10:31:55 +0200 Subject: [PATCH] Added document root when creating zip Thanks to paravibe on Drupal.org for contributing. --- h5p.classes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 0b2d7f8..660351c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1574,11 +1574,15 @@ Class H5PExport { $zip = new ZipArchive(); $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. foreach ($files as $file) { // Please note that the zip format has no concept of folders, we must // use forward slashes to separate our directories. $zip->addFile($file->absolutePath, $file->relativePath); + $zip->addFile($rootPrefix . $file->absolutePath, $file->relativePath); } // Close zip and remove tmp dir