diff --git a/website_code/php/import/import.php b/website_code/php/import/import.php index dad364ba8e..07f2040a5e 100644 --- a/website_code/php/import/import.php +++ b/website_code/php/import/import.php @@ -454,23 +454,39 @@ function test_unrecognised_import($test_array, $check) { foreach ($zip->compressedList as $x) { - foreach ($x as $y) { - if (!(strpos($y, "media/") === false)) { - $string = $zip->unzip($y, false, 0777); - $temp_array = array($y, $string, "media"); - array_push($file_data, $temp_array); - } + $y = $x['file_name']; + if (!(strpos($y, "media/") === false)) { + $string = $zip->unzip($y, false, 0777); + $file_to_create = array($y, $string, "media"); + if ($file_to_create[0] != "") { + $pos = strrpos($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], '/'); + if ($pos > 0) { + $dir = substr($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0, $pos); - if ((strpos($y, ".rlt") !== false)) { - $string = $zip->unzip($y, false, 0777); - $rlt_name = $y; - $temp_array = array($y, $string, "rlt"); - array_push($file_data, $temp_array); - if (!(strpos($string, "templateData=") === false)) { - $temp = substr($string, strpos($string, "templateData=\"FileLocation + '") + strlen("templateData=\"FileLocation + '")); - $temp = substr($temp, 0, strpos($temp, "'")); - $template_data_equivalent = $temp; + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } } + + $fp = fopen($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], "w"); + + fwrite($fp, $file_to_create[1]); + + fclose($fp); + + chmod($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0777); + } + } + + if ((strpos($y, ".rlt") !== false)) { + $string = $zip->unzip($y, false, 0777); + $rlt_name = $y; + $temp_array = array($y, $string, "rlt"); + array_push($file_data, $temp_array); + if (!(strpos($string, "templateData=") === false)) { + $temp = substr($string, strpos($string, "templateData=\"FileLocation + '") + strlen("templateData=\"FileLocation + '")); + $temp = substr($temp, 0, strpos($temp, "'")); + $template_data_equivalent = $temp; } } } @@ -483,16 +499,15 @@ function test_unrecognised_import($test_array, $check) { $preview_xml = ''; foreach ($zip->compressedList as $x) { - foreach ($x as $y) { - if ($y === $template_data_equivalent || $y === "template.xml") { - $data_xml = $zip->unzip($y, false, 0777); - $temp_array = array("data.xml", $data_xml, null); - array_push($file_data, $temp_array); - } else if ($y === "preview.xml") { - $preview_xml = $zip->unzip($y, false, 0777); - $temp_array = array("preview.xml", $preview_xml, null); - array_push($file_data, $temp_array); - } + $y = $x['file_name']; + if ($y === $template_data_equivalent || $y === "template.xml") { + $data_xml = $zip->unzip($y, false, 0777); + $temp_array = array("data.xml", $data_xml, null); + array_push($file_data, $temp_array); + } else if ($y === "preview.xml") { + $preview_xml = $zip->unzip($y, false, 0777); + $temp_array = array("preview.xml", $preview_xml, null); + array_push($file_data, $temp_array); } }