using zipArchive addFile() will not add image to zip

后端 未结 4 1019
迷失自我
迷失自我 2021-01-04 14:01

I\'ve been at this for a while. This actually worked one time, then never again. it simply does not create the zip file. The file does exist.

$zip = new          


        
4条回答
  •  天命终不由人
    2021-01-04 14:16

    The ZipArchive::addFile() method accepts the path to the file as its first parameter, but not all paths are created equal. addFile() method silently rejects the file and you never know what went wrong. As can be derived from the question, an alternative approach would be:

    // $zip->addFile($file);
    $content = file_get_contents($file);
    $zip->addFromString(pathinfo ( $file, PATHINFO_BASENAME), $content);
    

    In addition to getting the code working, file_get_contents() also generates decent error messages.

提交回复
热议问题