Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Something wrong with ZIP

Comments in 'Plugin Development' started by xiaoq, May 20, 2015.

  1. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I don't know why it not work?
    PHP:
            $zipPath $this->getDataFolder($this->getServer()->getDataPath() . "worlds/map.zip");
                
    $zip = new \ZipArchive;
                
    $result $zip->open($zipPath);
            
    $zip->extractTo($this->getServer()->getDataPath() . "worlds/");
                
    $zip->close();
    This is the error I got:
    [WARNING] RuntimeException: "ZipArchive::extractTo(): Invalid or uninitialized Zip object" (E_WARNING) in "/exampleplugin/src/Main" at line 57
  2. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Try $zip = new ZipArchive();
  3. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Now it have another error :
    [CRITICAL] ClassNotFoundException: "Class exampleplugin\ZipArchive not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144
  4. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    PHP:
    $zip = new \ZipArchive();
    LDX and CraftYourBukkit like this.
  5. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    If you want use classes already added in php library use \ before class name
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That's the same. Nothing changed.
    Maybe because the ZIP file doesn't exist or is corrupted?
    Try doing
    PHP:
    var_dump(is_file($this->getServer()->getDataPath() . "worlds/map.zip"));
    Thunder33345 likes this.
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Not the same. In one case it was missing parenthesis. In other missing back slash.

    Punctuation is important in computer languages.
    LDX likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I meant new \ZipArchive and new \ZipArchive() are the same in PHP.
  9. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    [WARNING] RuntimeException: "ZipArchive:Open(): Empty string as source" (E_WARNING) in "/exampleplugin/src/Main" at line 56
    this is the error I got after I try this
    PHP:
            $zipPath=var_dump(is_file($this->getServer()->getDataPath() . "worlds/map.zip"));
            
    $zip = new \ZipArchive;
                
    $result $zip->open($zipPath);
            
    $zip->extractTo($this->getServer()->getDataPath() . "worlds/");
                
    $zip->close();
  10. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Same Error
    [WARNING] RuntimeException: "ZipArchive::extractTo(): Invalid or uninitialized Zip object" (E_WARNING) in "/exampleplugin/src/Main" at line 57
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why did you use var_dump()? var_dump() returns void. I told you to use var_dump(is_file()) to check whether the file exists, not to use it as $zipPath!
  12. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Example please:)
  13. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Sorry, used to Java :).
    Andrey Nazarchuk likes this.
  14. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq

Share This Page

Advertisement