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 8115583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:31:14+00:00 2026-06-06T03:31:14+00:00

Can I include a file from a zip file in PHP? For example consider

  • 0

Can I include a file from a zip file in PHP? For example consider I have a zip file – test.zip and test.zip contains a file by the name a.php. Now, what I would like to do is something like below,

include “test.zip/a.php”;

Is this possible? If it is can anyone provide me a code snippet?? If not, id there any other alternative to do this??

  • 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-06T03:31:15+00:00Added an answer on June 6, 2026 at 3:31 am
    $zip = new ZipArchive('test.zip');
    
    $tmp = tmpfile();
    $metadata = stream_get_meta_data($tmp);
    
    file_put_content($metadata['uri'], $zip->getFromName('a.php'));
    
    include $metadata['uri'];
    

    To go further, you may be interested in PHAR archive, which basically a Zip archive.

    Edit:

    With a cache strategy:

    if (apc_exists('test_zip_a_php')) {
        $content = apc_fetch('test_zip_a_php');
    } else {
        $zip = new ZipArchive('test.zip');
        $content = $zip->getFromName('a.php');
        apc_add('test_zip_a_php', $content);
    }
    
    $f = fopen('php://memory', 'w+');
    fwrite($f, $content);
    rewind($f);
    // Note to use such include you need  `allow_url_include` directive sets to `On`
    include('data://text/plain,'.stream_get_contents($f));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: get name of current PHP script in include file Can an included
I would like to know how i can include files from multiple locations in
Can I include a file from a subdirectory, but have it placed in the
I would like to know if I can include some Jquery inside another JQuery
How can I tell if return() was called from within the included file. The
How can I include an HTML file in another HTML file. Is there any
Can I include the rt.jar in my executable jar file and double click to
While writing a .jsp file, can i include all the html5 tags in it
Here is what I have- How I can include multiple keys and their values
When connecting to a Sql Server you can include either App or Application Name

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.