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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:16:17+00:00 2026-06-10T20:16:17+00:00

I have a function which creates a zip file. function zipDoc($docRoot,$archiveName,$testsFolder){ $filename = tempnam($testsFolder,

  • 0

I have a function which creates a zip file.

function zipDoc($docRoot,$archiveName,$testsFolder){
$filename = tempnam($testsFolder, "doc");
$cwd=getcwd();
chdir ($docRoot);


 if (is_writeable($docRoot)){
    echo $docRoot." is writeable";
  }
    $zip = new ZipArchive();
    if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
        exit("cannot open <$filename>\n");
    }
  echo "<br/>";
  if (is_writeable(dirname($filename))){
    echo dirname($filename)." is writeable";
  }
    $folders = array ("_rels","docProps","word");
    // initialize an iterator
    // pass it the directory to be processed
    foreach ($folders as $folder){
        $iterator = new RecursiveIteratorIterator(new    RecursiveDirectoryIterator($folder."/"));
        // iterate over the directory
        // add each file found to the archive
        foreach ($iterator as $key=>$value) {
      if (!is_readable($key)){
           echo  "File ".$key." not readeble";
      }
            $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
        }
    }
    $zip->addFile("[Content_Types].xml");

    // close and save archive
    echo "<br/>";
  if ($zip->close()){
  echo $filename." is Closed";
  }
  else{
  echo $filename." is not closed";
  }
    $newname=str_replace(".tmp",".docx",$filename);
    rename($filename,$newname);
    chdir($cwd);
    return $newname;
}

The output is that both folders are writeable (I checked that on filesystem as well), and that the zip file is not closed!!!
Any suggestions, why is it not closing?
Edit: Status of file after close() method call is 3670068, function rename says that file is being used by another process. The file is created but has 0kb.

  • 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-10T20:16:19+00:00Added an answer on June 10, 2026 at 8:16 pm

    OK, I found a solution:
    When adding files from folders to a zip-file I missed to check if it is a real file, or just a link to current or parent folder eg.: /. or /..
    After adding this simple check when iterating files, everything works fine.

    if (substr($key,-1)=="."){
                    continue;
                }
    

    Hope somebody will use this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which creates an object of values, but im getting this
I have the following function which creates a std::vector of iterators into another container:
I have a button which creates form elements on click . My addelement function
I have a function which creates an array of Maps: map<string, int> *pMap And
So I have a function which creates a dynamic model. I accomplish this in
I have a zip file which can contain any number of zipfiles inside it
I have a function which creates Pointer to a data from a Stream. function
I have a function which creates a SELECT statement with a WHERE clause. This
I have a function which creates a tooltip for specific objects. Currently, I am
I have a function which creates a report and sends it to a user.

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.