zip命令无法在php中工作

时间:2014-12-12 10:12:38

标签: php zip

我正在尝试在我的网站上构建应用程序,我可以上传rar文件并将其解压缩并将其内容存储在名为uploads的文件夹中,该文件夹位于代码所在的同一文件夹中。但是我运行我的脚本我得到了以下错误。 我的php版本是5.5.11 警告:ZipArchive :: extractTo():第21行的C:\ xampp \ htdocs \ zip \ new.php中无效或统一的Zip对象

警告:ZipArchive :: close():第22行的C:\ xampp \ htdocs \ zip \ new.php中的Zip对象无效或单元化 我的代码如下

<?php
if(isset($_FILES['zip'])){
    //defined an error erray
    $errors=array();
    $zip = new ZipArchive();
    print_r($_FILES['zip']);
    //taking the extention of the last file (in lower case) of the zip file
    if(strtolower(end(explode('.',$_FILES['zip']['name'])))!=='rar'){
        $errors[]="this is not a zip file";
        echo "file is not opened";
    }
    //if file bigger than 100mb
    if($_FILES['zip']['size']>104857600){
        $errors[]="there is a size limit of 100 mb";
    }
    if($zip->open($_FILES['zip']['tmp_name'])===TRUE){
        echo "file is opened";
        $errors[]="failed to open zip file";
    }
    if(empty($errors)){
        $zip->extractTo('uploads');
        $zip->close();
    }
}
?>
<html>
    <body>
        <form action="" method="POST" enctype="multipart/form-data">
            <div>
                <input type="file" name="zip"/>
                <input type="submit" value="Upload"/>
            </div>
        </form>
    </body>
</html>

0 个答案:

没有答案