【问题标题】:ziparchive() issue in server服务器中的 ziparchive() 问题
【发布时间】:2018-12-12 06:10:19
【问题描述】:

我无法使用 ziparchive() 创建 .zip 文件 我正在使用下面的代码

$zip = new ZipArchive();
$filename = "./mynewzip.zip";

if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    echo ("<script LANGUAGE='JavaScript'> window.alert('Error opening zip archive...!'); window.location.href='http://work.chaturlocal.com/shop/<?php echo $shop_id; ?>'; </script>");
}

$dir = 'includes/';

// Create zip
createZip($zip,$dir);

$zip->close();

function createZip($zip,$dir){
if (is_dir($dir)){

    if ($dh = opendir($dir)){
        while (($file = readdir($dh)) !== false){

            // If file
            if (is_file($dir.$file)) {
                if($file != '' && $file != '.' && $file != '..'){

                    $zip->addFile($dir.$file);
                }
            }else{
                // If directory
                if(is_dir($dir.$file) ){

                    if($file != '' && $file != '.' && $file != '..'){

                        // Add empty directory
                        $zip->addEmptyDir($dir.$file);

                        $folder = $dir.$file.'/';

                        // Read data of the folder
                        createZip($zip,$folder);
                    }
                }

            }

        }
        closedir($dh);
    }
}
}

代码在具有 php 版本 7 的 localhost 中完美运行。 但不能在 使用 php 5.4.1 的服务器中工作。 我使用“php-zip”安装了 zip 库,但无法执行命令“phpenmod zip”。 请让我知道解决方案。 谢谢。

【问题讨论】:

    标签: php linux centos ziparchive


    【解决方案1】:

    将 php.ini 更新为

    extension=zip.so
    

    下面

    ; extension=msql.so
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      • 2020-05-19
      • 2014-03-08
      • 2019-12-11
      • 2013-03-31
      相关资源
      最近更新 更多