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

  • SEARCH
  • Home
  • 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 8557927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:41:15+00:00 2026-06-11T15:41:15+00:00

I am trying to upload the zip file but it is not able to

  • 0

I am trying to upload the zip file but it is not able to upload but when I try uploading other type extension file, it is uploaded correctly. Following is the code for uploading files the zip files:

<?php  

    if(isset($_FILES['fupload'])) {  
        $filename = $_FILES['fupload']['name'];  
        $source = $_FILES['fupload']['tmp_name'];  
        $type = $_FILES['fupload']['type'];  
        $name = explode('.', $filename);  
        $target = 'extracted/' . $name[0] . '-' . time() . '/';  
        // Ensures that the correct file was chosen  
        $accepted_types = array('application/zip',  
                                    'application/x-zip-compressed',  
                                    'multipart/x-zip',  
                                    'application/s-compressed');  
        foreach($accepted_types as $mime_type) {  
            if($mime_type == $type) {  
                $okay = true;  
                break;  
            }  
        }  
      //Safari and Chrome don't register zip mime types. Something better could be used here.  
        $okay = strtolower($name[1]) == 'zip' ? true: false; 
        if(!$okay) { 
              die("Please choose a zip file, dummy!"); 
        } 
        mkdir($target); 
        $saved_file_location = $target . $filename; 
        if(move_uploaded_file($source, $saved_file_location)) { 
            openZip($saved_file_location); 
        } else { 
            die("There was a problem. Sorry!"); 
        } 
    // This last part is for example only. It can be deleted. 
        $scan = scandir($target . $name[0]); 
        print '<ul>'; 
        for ($i = 0; $i<count($scan); $i++) { 
            if(strlen($scan[$i]) >= 3) { 
                $check_for_html_doc = strpos($scan[$i], 'html'); 
                $check_for_php = strpos($scan[$i], 'php'); 
                if($check_for_html_doc === false && $check_for_php === false) { 
                    echo '<li>' . $scan[$i] . '</li>'; 
                } else { 
                    echo '<li><a href="' . $target . $name[0] . '/' . $scan[$i] . '">' . $scan[$i] . '</a></li>'; 
                } 
            } 
        } 
        print '</ul>';  
    }  
    ?>  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>  
   <head>  
      <title>How to Upload and Open Zip Files With PHP</title>  
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
   </head>  
   <body>  
      <div id="container">  
      <h1>Upload A Zip File</h1>  
      <form enctype="multipart/form-data" action="" method="post">  
      <input type="file" name="fupload" /><br />  
      <input type="submit" value="Upload Zip File" />  
      </form>  
      </div><!--end container-->  
    </body>  
</html>  
  • 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-11T15:41:16+00:00Added an answer on June 11, 2026 at 3:41 pm

    you have to use

    if(is_dir($target . $name[0]))
    {
    
      $scan = scandir($target . $name[0]);
    
    }else{
    
     $scan = scandir($target);
    } 
    

    inseted of

     $scan = scandir($target . $name[0]);
    

    and increase memory_limit, 'upload_max_filesize, post_max_size, max_input_time and max_execution_timeetc.

    Below code use in your php file.

    ini_set( 'memory_limit', '128M' );
    ini_set('upload_max_filesize', '128M');  
    ini_set('post_max_size', '128M');  
    ini_set('max_input_time', 3600);  
    ini_set('max_execution_time', 3600);
    

    Or set below code in .htaccess file

    php_value upload_max_filesize 128M  
    php_value post_max_size 128M  
    php_value max_input_time 3600  
    php_value max_execution_time 3600 
    

    I have modify you code please try it.

     <?php  
    
    
    
    ini_set( 'memory_limit', '128M' );
    ini_set('upload_max_filesize', '128M');  
    ini_set('post_max_size', '128M');  
    ini_set('max_input_time', 3600);  
    ini_set('max_execution_time', 3600);
    
    function openZip($file_to_open) {  
        global $target;  
        $zip = new ZipArchive();  
        $x = $zip->open($file_to_open);  
        if($x === true) {  
            $zip->extractTo($target);  
            $zip->close();  
            unlink($file_to_open);  
        } else {  
            die("There was a problem. Please try again!");  
        }  
    } 
    
        if(isset($_FILES['fupload'])) {  
            $filename = $_FILES['fupload']['name'];  
            $source = $_FILES['fupload']['tmp_name'];  
            $type = $_FILES['fupload']['type'];  
            $name = explode('.', $filename);  
            $target = 'extracted/' . $name[0] . '-' . time() . '/';  
            // Ensures that the correct file was chosen  
            $accepted_types = array('application/zip',  
                                        'application/x-zip-compressed',  
                                        'multipart/x-zip',  
                                        'application/s-compressed');  
            foreach($accepted_types as $mime_type) {  
                if($mime_type == $type) {  
                    $okay = true;  
                    break;  
                }  
            }  
          //Safari and Chrome don't register zip mime types. Something better could be used here.  
            $okay = strtolower($name[1]) == 'zip' ? true: false; 
            if(!$okay) { 
                  die("Please choose a zip file, dummy!"); 
            } 
            mkdir($target); 
            $saved_file_location = $target . $filename; 
            if(move_uploaded_file($source, $saved_file_location)) { 
                openZip($saved_file_location); 
            } else { 
                die("There was a problem. Sorry!"); 
            } 
    
            if(is_dir($target . $name[0]))
            {
    
              $scan = scandir($target . $name[0]);
    
            }else{
    
                $scan = scandir($target);
            } 
            print '<ul>'; 
            for ($i = 0; $i<count($scan); $i++) { 
                if(strlen($scan[$i]) >= 3) { 
                    $check_for_html_doc = strpos($scan[$i], 'html'); 
                    $check_for_php = strpos($scan[$i], 'php'); 
                    if($check_for_html_doc === false && $check_for_php === false) { 
                        echo '<li>' . $scan[$i] . '</li>'; 
                    } else { 
                        echo '<li><a href="' . $target . $name[0] . '/' . $scan[$i] . '">' . $scan[$i] . '</a></li>'; 
                    } 
                } 
            } 
            print '</ul>';  
        }  
        ?>  
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
        <html>  
          <head>  
            <title>How to Upload and Open Zip Files With PHP</title>  
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
          </head>  
          <body>  
            <div id="container">  
            <h1>Upload A Zip File</h1>  
            <form enctype="multipart/form-data" action="" method="post">  
                <input type="file" name="fupload" /><br />  
                <input type="submit" value="Upload Zip File" />  
            </form>  
            </div><!--end container-->  
          </body>  
        </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload images to a php file, everything works, but sometimes when
I'm trying to upload a file .txt in my web space, but then the
I have this file: C:\Documents and Settings\tc\My Documents\Downloads\ee_server_wizard.zip and I am trying to upload
For some reason when trying to upload a zip file this function always returns
When I try to upload a file in PHP, It will not let me.
I am trying to, with Ant, upload a zip-file via FTP to a Windows
i'm trying upload image and mp3 in the same form but image is uploaded
I'm trying to use a python script to upload a zip file to a
I trying to upload a zip file. In my project i am using DWR
I am trying to upload an archive file (a Zip archive if that matters)

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.