当前位置: 首页>>代码示例>>PHP>>正文


PHP ZipArchive::getfromName方法代码示例

本文整理汇总了PHP中ZipArchive::getfromName方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::getfromName方法的具体用法?PHP ZipArchive::getfromName怎么用?PHP ZipArchive::getfromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZipArchive的用法示例。


在下文中一共展示了ZipArchive::getfromName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleupload

function handleupload(&$errors, &$warnings, &$messages)
{
    if (empty($_FILES) || empty($_FILES["file"])) {
        $errors[] = "No file was uploaded";
        return false;
    }
    if ($_FILES["file"]["error"]) {
        $errors[] = "There was a problem uploading the file — try again in a short while";
        return false;
    }
    switch ($_FILES["file"]["type"]) {
        case "application/xml":
        case "text/xml":
        case "application/qti+xml":
            $metadata = array();
            $filename = $_FILES["file"]["name"];
            $xml = file_get_contents($_FILES["file"]["tmp_name"]);
            break;
        case "application/zip":
        case "application/x-zip-compressed":
        case "application/x-zip":
            // open zip file
            $zip = new ZipArchive();
            if ($zip->open($_FILES["file"]["tmp_name"]) !== true) {
                $errors[] = "Failed to open the zip file. Ensure it is not corrupt and try again.";
                return false;
            }
            // get manifest, make sure it's valid XML
            $mxml = $zip->getfromName("imsmanifest.xml");
            if ($mxml === false) {
                $errors[] = "Error getting manifest file -- are you sure this is a content package?";
                return false;
            }
            $mxml = simplexml_load_string($mxml);
            if ($mxml === false) {
                $errors[] = "The manifest file in the uploaded content package is not valid XML";
                return false;
            }
            $metadata = array();
            // get manifest identifier
            $metadata["midentifier"] = (string) $mxml["identifier"];
            // ensure there's only one resource
            $resource = $mxml->resources->resource;
            if (count($resource) > 1) {
                $errors[] = "More than one resource element found in the manifest -- this is not a single-item content package";
                return false;
            }
            if (count($resource) == 0) {
                $errors[] = "No resource elements found in the manifest -- this is not a single-item content package";
                return false;
            }
            // ensure it's an item rather than an assessment
            if (!preg_match('%^imsqti_item_%', (string) $resource["type"])) {
                $errors[] = "This content package contains an assessment test rather than an assessment item";
                return false;
            }
            // get the metadata
            $imsmd = $resource->metadata->children(NS_IMSMD);
            if (isset($imsmd->lom->general->description->langstring[0])) {
                $metadata["description"] = (string) $imsmd->lom->general->description->langstring[0];
            }
            $metadata["keywords"] = array();
            foreach ($imsmd->lom->general->keyword as $keyword) {
                $metadata["keywords"][] = (string) $keyword->langstring[0];
            }
            // get the file pointed to
            $filename = (string) $resource["href"];
            $xml = $zip->getfromName($filename);
            if ($xml === false) {
                $errors[] = "Error getting item file \"{$filename}\" from archive";
                return false;
            }
            break;
        default:
            $errors[] = "The uploaded file (of type " . $_FILES["file"]["type"] . ") was not recognized as a content package (zip) or QTI XML file.";
            return false;
    }
    return array($xml, $metadata);
}
开发者ID:rprince,项目名称:eqiat,代码行数:79,代码来源:functions.php


注:本文中的ZipArchive::getfromName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。