Проблема с ziparchive () на сервере - PullRequest
0 голосов
/ 12 декабря 2018

Я не могу создать файл .zip с помощью ziparchive (). Я использую фрагмент кода ниже

$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 .Я установил zip-библиотеку, используя « php-zip », не могу выполнить команду « phpenmod zip ».Пожалуйста, дайте мне знать решение.Спасибо.

1 Ответ

0 голосов
/ 13 декабря 2018

Обновлен php.ini как

extension=zip.so

Ниже

; extension=msql.so
...