/** * Function processZip * * * @param $fileName * @return string */ function processZip($fileName) { $out = ''; $_SESSION['failCount'] = 0; $zipName = basename($fileName); $zip = new ZipArchive(); $res = $zip->open($fileName); if ($res === TRUE) { $numFiles = $zip->numFiles; for ($loop = 0; $loop < $numFiles; $loop++) { $curName = $zip->getNameIndex($loop); if (strstr($curName, '/') !== false) { $endPos = strrpos($curName, '/') + 1; $curName = substr($curName, $endPos); } if (empty($curName)) { continue; } $fp = $zip->getStream($zip->getNameIndex($loop)); if (!$fp) { $out .= "Processing for {$curName} failed.<br />\n"; $bad_aiml_files = !isset($bad_aiml_files) ? array() : $bad_aiml_files; $bad_aiml_files[] = $curName; $_SESSION['bad_aiml_files'] = $curName; } else { $curText = ''; while (!feof($fp)) { $curText .= fread($fp, 8192); } fclose($fp); if (!stristr($curName, '.aiml')) { continue; } $out .= parseAIML($curName, $curText, true); } } $zip->close(); $failCount = $_SESSION['failCount']; $out .= "<br />\nUpload complete. {$numFiles} files were processed, and {$failCount} files encountered errors.<br />\n"; if (isset($_SESSION['bad_aiml_files'])) { $out .= "<br />\nThe following AIML files encountered errors:<br />\n"; foreach ($_SESSION['bad_aiml_files'] as $fn) { $out .= "{$fn}, "; } $out = rtrim($out, ', ') . "<br .>\nPlease test each of these files independently, to locate the errors within."; unset($_SESSION['bad_aiml_files']); } } else { $out = "Upload failed. {$fileName} was either corrupted, or not a zip file."; } return $out; }
function processZip($fileName) { $out = ''; $zipName = basename($fileName); $zip = new ZipArchive(); $res = $zip->open($fileName); if ($res === TRUE) { $numFiles = $zip->numFiles; for ($loop = 0; $loop < $numFiles - 1; $loop++) { $curName = $zip->getNameIndex($loop); if (strstr($curName, '/') !== false) { $endPos = strrpos($curName, '/') + 1; $curName = substr($curName, $endPos); } if (empty($curName)) { continue; } $fp = $zip->getStream($zip->getNameIndex($loop)); if (!$fp) { $out .= "Processing for {$curName} failed.<br />\n"; } else { $curText = ''; while (!feof($fp)) { $curText .= fread($fp, 8192); } fclose($fp); $out .= "Processing file {$curName}<br />\n"; if (!stristr($curName, '.aiml')) { $out .= "file {$curName} is not an AIML file - Ignoring.<br />\n"; continue; } $out .= parseAIML($curName, $curText); } } $zip->close(); $out .= "Upload complete. {$numFiles} files were processed.<br />\n"; } else { $out = "Upload failed. {$fileName} was either corrupted, or not a zip file."; } return $out; }