No error when creating zip, but it doesn't get created

前端 未结 6 1354
醉梦人生
醉梦人生 2021-02-18 15:38

I wrote this code to create a ZIP file and to save it. But somehow it just doesn\'t show any error, but it doesn\'t create a ZIP file either. Here\'s the code:

$         


        
6条回答
  •  自闭症患者
    2021-02-18 16:05

    I had an exactly same issue, even when with full writing/reading permissions.

    Solved by creating the ".zip" file manually before passing it to ZipArchive:

    $zip = new ZipArchive;
    $time = microtime(true);
    $path = "maps/zips/test_" . $time . ".zip"
    
    touch($path);  //<--- this line creates the file
    
    $res = $zip->open($path, ZipArchive::CREATE);
    if ($res === TRUE) {
        echo "RESULT TRUE...";
        $zip->addFile("maps/filename.ogz","filename.ogz"); //Sauerbraten map format
        $zip->addFromString('how_to_install.txt', 'Some Explanation...');
        $zip->close();
        $zip_created = true;
        echo "FILE ADDED!";
    }
    

提交回复
热议问题