How to change the name of the file during unzip?

102 views Asked by At

I need to change the name of the file with current time or something else when unzipping, and need to save the file.

I know to unzip the file and saving using the function

unzip_file()

But I need to change the file name before save.

1

There are 1 answers

0
Domain On

Try this:

$zip = new ZipArchive;
if($zip->open($path) === TRUE) {
   $name = $zip->getNameIndex(0);
   $zip->extractTo($destination);
   $zip->close();
}
$ext = pathinfo("/destination/$name", PATHINFO_EXTENSION);
rename("/destination/$name" . $ext, "/destination/$new_name" . $ext);