douniangliao4327 2019-06-03 13:02
浏览 439

在extractTo函数中传递路径显示错误:PHP中的Zip对象无效或未初始化

I have a foldername afile, inside this folder I have checkfiles.php and allFiles folder which contains two zip files. Actually I am trying to unzip the two zip files, looping those zip files in foreach loop and want to open those folders and the folder contains config.xml file.

In this config.xml file I want to replace some text. I have written a code in checkfiles.php file and executing in the command prompt but it throwing error like Invalid or uninitialized Zip object where extractTo() function is written. I am using Ubuntu OS.

Here is my code

<?php
    $folderName = 'allFiles';
        $dir = opendir($folderName);
    if($dir)
    {
       while( ($file_name = readdir($dir))!== FALSE )
       {
          if($file_name != '.' && $file_name != '..')
          {
             $file[] = $file_name;

          }

       }         
    }

        foreach ($file  as $allfile) { 
         $zip = new ZipArchive();
          $res = $zip->open($allfile);
          $zip->extractTo($folderName);
        $existFile = file_exists('config.xml');             
          if($existFile)
          {
                $fileForWrite = fopen("config.xml","w") or die("Unable to open file!");

                while(!feof($fileForWrite)) { 

                //Check highlightalpha="0.6" exists then replace with highlightalpha="0.3"        
                $file_contents = file_get_contents($fileForWrite);
                $file_contents_replaced = str_replace('highlightalpha="0.6"','highlightalpha="0.3"',$file_contents);
                file_put_contents($fileForWrite,$file_contents_replaced); 
                fclose($fileForWrite);

                echo fgets($fileForWrite) . "<br>";

                }
                fclose($fileForWrite);

          } 



       } 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏