PHP ZipArchive停止工作

PHP ZipArchive停止工作,php,csv,zip,Php,Csv,Zip,我有一个脚本,它获取压缩的CSV文件,解压它,并删除重复的条目。在我将解压代码移动到一个函数中之前,它基本上是工作的。现在它无法解压缩.zip文件,但没有显示错误 已检查文件/文件夹权限,dev计算机上的所有内容均为777 <?php // //huge memory limit for large files $old = ini_set('memory_limit', '8192M'); // //create a string like the filename $base_file

我有一个脚本,它获取压缩的CSV文件,解压它,并删除重复的条目。在我将解压代码移动到一个函数中之前,它基本上是工作的。现在它无法解压缩.zip文件,但没有显示错误

已检查文件/文件夹权限,dev计算机上的所有内容均为777

<?php
//
//huge memory limit for large files
$old = ini_set('memory_limit', '8192M');
//
//create a string like the filename
$base_filename = 'csv-zip-file'.date('m').'_'.date('d').'_'.date('Y');
//
//if the file exists ...
//unzip it
//read it to an array
//remove duplicates
//save it as a new csv
if (file_exists($base_filename.'.zip')) {
    $zip_filename = $base_filename.'.zip';
    echo "The file <strong>$zip_filename</strong> exists<br>";
    unzip($zip_filename);
    $csv = csv_to_array();
    $csv = unique_multidim_array($csv,"Project Id");
    var_dump($csv);
} else {
    echo "The file <strong>$base_filename.zip</strong> does not exist";
}


function unzip($file_to_unzip) {
    $zip=new ZipArchive();
    if($zip->open($file_to_unzip)==TRUE) {
        $address=__DIR__;
        $zip->extractTo($address);
        $res=$zip->close();
        echo 'ok';
    }
    else{
        echo 'failed';
    }
}

function unique_multidim_array($array, $key) {
    $temp_array = array();
    $i = 0;
    $key_array = array();
    foreach($array as $val) {
        if (!in_array($val[$key], $key_array)) {
            $key_array[$i] = $val[$key];
            $temp_array[$i] = $val;
        }
        $i++;
    }
    return $temp_array;
}

function csv_to_array () {
//    global $filename;
    global $base_filename;
    $rows = array_map('str_getcsv', file($base_filename.'.csv'));
    //using array_pop to remove the copyright on final row
    array_pop($rows);
    $header = array_shift($rows);
    $csv = array();
    foreach ($rows as $row) {
        $csv[] = array_combine($header, $row);
    }
    return $csv;
}

这里有一个有趣的问题

  • 输出
    $file\u到\u解压
    函数内部
  • $zip->*是否有
    last\u错误
    last\u响应
    方法?看见 ZipArchive类正在返回的内容
  • 您有权访问php错误日志吗?让我们看看有没有输出

  • 旁注:这是一个奇怪的内存分配。对于第1项,假设您的意思是“echo$file\u to\u unzip;”,看起来不错。我检查了zip的方法,有一个“getStatusString”方法,当我查看错误日志时,它说:PHP警告:ZipArchive::getStatusString():初始化ZipArchive对象后,ZipArchive对象无效或未初始化,请一步一步地,一行一行地,按照您希望的方式完成整个过程。找到它按预期停止工作的位置。这听起来像是一个范围问题。