Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:49:33+00:00 2026-06-05T08:49:33+00:00

I am using a php script to unzip ZIP file. but this script unzip

  • 0

I am using a php script to unzip ZIP file. but this script unzip only one level of directories without extracting the sub directories of that file
the script:

$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}

for example: if the test.zip contains 2 folders: folder1\file.png, folder2\folder3\file3.png

after extracting this ZIP file, i only see the folder1*.* and folder2*.* but without the sub directory folder3.

How can i improve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:49:35+00:00Added an answer on June 5, 2026 at 8:49 am

    I think this PHP manual will be helpful to you
    http://php.net/manual/en/ref.zip.php

    <?php
    $file = "2537c61ef7f47fc3ae919da08bcc1911.zip";
    $dir = getcwd();
    function Unzip($dir, $file, $destiny="")
    {
        $dir .= DIRECTORY_SEPARATOR;
        $path_file = $dir . $file;
        $zip = zip_open($path_file);
        $_tmp = array();
        $count=0;
        if ($zip)
        {
            while ($zip_entry = zip_read($zip))
            {
                $_tmp[$count]["filename"] = zip_entry_name($zip_entry);
                $_tmp[$count]["stored_filename"] = zip_entry_name($zip_entry);
                $_tmp[$count]["size"] = zip_entry_filesize($zip_entry);
                $_tmp[$count]["compressed_size"] = zip_entry_compressedsize($zip_entry);
                $_tmp[$count]["mtime"] = "";
                $_tmp[$count]["comment"] = "";
                $_tmp[$count]["folder"] = dirname(zip_entry_name($zip_entry));
                $_tmp[$count]["index"] = $count;
                $_tmp[$count]["status"] = "ok";
                $_tmp[$count]["method"] = zip_entry_compressionmethod($zip_entry);
    
                if (zip_entry_open($zip, $zip_entry, "r"))
                {
                    $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                    if($destiny)
                    {
                        $path_file = str_replace("/",DIRECTORY_SEPARATOR, $destiny . zip_entry_name($zip_entry));
                    }
                    else
                    {
                        $path_file = str_replace("/",DIRECTORY_SEPARATOR, $dir . zip_entry_name($zip_entry));
                    }
                    $new_dir = dirname($path_file);
    
                    // Create Recursive Directory (if not exist)  
                    if (!file_exists($new_dir)) {
                      mkdir($new_dir, 0700);
                    }
    
                    $fp = fopen($dir . zip_entry_name($zip_entry), "w");
                    fwrite($fp, $buf);
                    fclose($fp);
    
                    zip_entry_close($zip_entry);
                }
                echo "\n</pre>";
                $count++;
            }
    
            zip_close($zip);
        }
    }
    Unzip($dir,$file);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display an image using this php script on my server. $file
How to process files inside the folder sub directories using php script. Actually I
Is it possible to make changes in mysql's my.ini file using PHP script?
I'm using old php script that depends on session_register to gives warning messages but
I need to handle strings in my php script using regular expressions. But there
I am trying to send an e-mail using php script but i am getting
I am using php script to upload file on some ftp server. When I
I am trying to upload a file of 1GB size using php script and
I need a small information regarding executing a .exe file using PHP script. I
I am trying to connect to MySQL DB using php script. But I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.