Hello!

I have a zip file containing the following files:

file1.bin
file2.bin
file3.bin
file4.bin etc..

I use this code to unzip the files:

$zip_file_name="all_files_".$time.".zip";

$zip = new ZipArchive;
$res = $zip->open($zip_file_name);

if ($res === TRUE) {

chmod("unzip\", 0644);

$zip->extractTo('unzip/');
$zip->close();

	}
else {

echo "Could not open file";
}

But how can I unzip only one particular file for instance file4.bin?

Thanks!!

    Thank you for reply! I have tried this 🙁 For some reason it does not work. Is it because my file name contains all kinds of underscore etc..:

    for instance:

    $file_to_extract="file4_32476-87454.bin";
    ....
    --->

    $zip->extractTo('unzip/', $file_to_extract);
    ...

      If you think that is the problem, then try an archive in which the file name is simpler and see if it makes a difference.

        Yes.... it works with a simple file name... What should I do? I cannot help for those file names to be complicated. If nothing can be done, I could unzip all the files and delete the ones I dont need ? 🙂 bad solution though

          There was a bug with utf-8 filenames in 5.3.something_or_other. If this is your issue, update to a current version and it is probably fixed.

          While there are usually no problems with handling most characters in filenames, if you ever want to be certain of it, I recommend sticking to a-z and A-Z as well as underscore _. In other words, remove the hyphen -.

          Other than that, you could perhaps iterate over the contents and retrieve each filename to see what it looks like. Perhaps it all works but you are not using the same encoding? Or there is some kind of screw up in the archive which may show when inspecting the filenames.

          If all else fails, I'd rather extract everything, change all the problematic filenames and then rezip it all. I don't like solving the same problem more than once.

            Write a Reply...