Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php-使用*.csv文件中的日志提取zip文件_Php_Logging_Csv_Zip_Extract - Fatal编程技术网

Php-使用*.csv文件中的日志提取zip文件

Php-使用*.csv文件中的日志提取zip文件,php,logging,csv,zip,extract,Php,Logging,Csv,Zip,Extract,我需要一个php脚本,提取一个文件(与文件夹和子文件夹),并创建一个日志,其中插入一些有关提取文件的信息 现在,下面的脚本提取一个zip文件(包含文件夹和子文件夹),但只在csv文件中插入最后提取的文件信息。如何修复它以创建一个包含所有提取信息的文件列表 谢谢你的帮助 file = "test.zip"; $dir = getcwd(); function Unzip($dir, $file, $destiny="") { $dir .= DIRECTORY_SEPARATOR; $path_f

我需要一个php脚本,提取一个文件(与文件夹和子文件夹),并创建一个日志,其中插入一些有关提取文件的信息

现在,下面的脚本提取一个zip文件(包含文件夹和子文件夹),但只在csv文件中插入最后提取的文件信息。如何修复它以创建一个包含所有提取信息的文件列表

谢谢你的帮助

file = "test.zip";
$dir = getcwd();
function Unzip($dir, $file, $destiny="")
{
$dir .= DIRECTORY_SEPARATOR;
$path_file = $dir . $file;
$zip = zip_open($path_file);
$_tmp = array();
$count=0;
if ($zip)
{
    while ($zip_entry = zip_read($zip))
    {
        $_tmp[$count]["filename"] = zip_entry_name($zip_entry);
        $_tmp[$count]["stored_filename"] = zip_entry_name($zip_entry);
        $_tmp[$count]["size"] = zip_entry_filesize($zip_entry);
        $_tmp[$count]["compressed_size"] = zip_entry_compressedsize($zip_entry);
        $_tmp[$count]["mtime"] = "";
        $_tmp[$count]["comment"] = "";
        $_tmp[$count]["folder"] = dirname(zip_entry_name($zip_entry));
        $_tmp[$count]["index"] = $count;
        $_tmp[$count]["status"] = "ok";
        $_tmp[$count]["method"] = zip_entry_compressionmethod($zip_entry);

        if (zip_entry_open($zip, $zip_entry, "r"))
        {
            $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            if($destiny)
            {
                $path_file = str_replace("/",DIRECTORY_SEPARATOR, $destiny . zip_entry_name($zip_entry));
            }
            else
            {
                $path_file = str_replace("/",DIRECTORY_SEPARATOR, $dir . zip_entry_name($zip_entry));
            }
            $new_dir = dirname($path_file);

            mkdir($new_dir);

            $fp = fopen($dir . zip_entry_name($zip_entry), "w");
            fwrite($fp, $buf);
            fclose($fp);

            zip_entry_close($zip_entry);

        }
        echo "\n</pre>";
        $count++;
        $named = zip_entry_name($zip_entry);                            
        $outputfile = "log.csv";
        if (!$outfilefp = fopen($outputfile, "w"))
        die("<br>No write on $outputfile");
        else
        echo "<br>Add lines to csv file";
        $temp = array($path_file,$new_dir,$named);
        fputcsv($outfilefp, $temp, ";");
    }

    zip_close($zip);
}
}
  Unzip($dir,$file);
file=“test.zip”;
$dir=getcwd();
函数解压($dir,$file,$destiny=”“)
{
$dir.=目录\分隔符;
$path_file=$dir.$file;
$zip=zip\u打开($path\u文件);
$_tmp=array();
$count=0;
如果($zip)
{
而($zip\u entry=zip\u read($zip))
{
$\u tmp[$count][“filename”]=zip\u entry\u name($zip\u entry);
$\u tmp[$count][“存储的\u文件名”]=zip\u条目\u名称($zip\u条目);
$\u tmp[$count][“size”]=zip\u条目\文件大小($zip\u条目);
$\u tmp[$count][“compressed\u size”]=zip\u entry\u compressedsize($zip\u entry);
$\u tmp[$count][“mtime”]=”;
$\u tmp[$count][“comment”]=“”;
$\u tmp[$count][“folder”]=dirname(zip\u entry\u name($zip\u entry));
$\u tmp[$count][“index”]=$count;
$\u tmp[$count][“status”]=“ok”;
$\u tmp[$count][“method”]=zip\u entry\u compressionmethod($zip\u entry);
如果(zip_entry_open($zip,$zip_entry,“r”))
{
$buf=zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
如果($destiny)
{
$path_file=str_replace(“/”,目录分隔符,$destiny.zip_entry_name($zip_entry));
}
其他的
{
$path_file=str_replace(“/”,目录分隔符,$dir.zip_entry_name($zip_entry));
}
$new_dir=dirname($path_file);
mkdir($new_dir);
$fp=fopen($dir.zip_entry_name($zip_entry),“w”);
fwrite($fp,$buf);
fclose($fp);
zip_entry_close($zip_entry);
}
回音“\n”;
$count++;
$named=zip\u entry\u name($zip\u entry);
$outputfile=“log.csv”;
如果(!$outfilefp=fopen($outputfile,“w”))
die(“
未写入$outputfile”); 其他的 echo“
将行添加到csv文件”; $temp=array($path\u file,$new\u dir,$named); fputcsv($outfilefp,$temp,“;”); } zip_close($zip); } } 解压缩($dir,$file);
实际上它正在插入每一个文件,但每次都会覆盖最后一个插入的文件,因此您只能看到最后一个文件。的模式应为a而不是w

“w”仅限书写;将文件指针放在文件的开头 打开文件并将文件截断为零长度。如果文件没有 存在,尝试创建它

“a”只对写作开放;将文件指针放在 文件如果文件不存在,请尝试创建它