Using ZipArchive with PHP 8 and temporary files

The failure is being caused by the fact that the use of the tempnam function actually creates a zero byte file and that is what ZipArchive::CREATE is complaining about.

The solution was to unlink the temporary file created by tempnam before trying to use it. In the example in the question I simply added unlink($temp_file); immediately after $temp_file = tempnam(sys_get_temp_dir(),'AW');.

The first few lines now look like this:

$backupfile = BACKUPDIR . date('Ymd') . '.zip';
$temp_file  = tempnam(sys_get_temp_dir(),'AW');

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top