服务器中的ziparchive()问题

时间:2018-12-12 06:10:20

标签: php linux centos ziparchive

我无法使用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 ”。 请让我知道解决方案。 谢谢。

1 个答案:

答案 0 :(得分:0)

将php.ini更新为

extension=zip.so

下方
; extension=msql.so