gpt4 book ai didi

php - 服务器中的 ziparchive() 问题

转载 作者:太空宇宙 更新时间:2023-11-04 11:57:27 25 4
gpt4 key购买 nike

我无法使用 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);
}
}
}

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

最佳答案

将 php.ini 更新为

extension=zip.so

下面

; extension=msql.so

关于php - 服务器中的 ziparchive() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53737032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com