2
votes

Situation

  • I have a .zip file. In this .zip is a folder "dist/", in the folder "dist/" are 2 things: 1) another folder "lib/" 2) a jar-file
  • I open the .zip and extract the dist/jar-file. A "new" folder will appear on my disk "dist" with the jar in it
  • I open the jar-file with ZipArchive and edit this where needed. Edits are saved by addFromString()

Now comes the crucial part

  • I want to re-add the jar-file into the .zip
  • I do this by doing $zip->addFile($newdir . 'dist/' . $corefile, 'dist/' . $corefile)

where:

  • $newdir is the absolute path to the "new" dist/ folder with the extracted/edited jar-file in, on my local disk
  • $corefile is the filename of the extracted/used jar-file
  • I want to add the edited jar-file into the dist/ folder inside the zip

What happens

  • The jar-file is successfully edited
  • No errors are given while adding the jar back into the .zip
  • When I open the modified .zip and .jar, nothing is changed.

What am I doing wrong?

Thanks!

--EDIT:

Found the problem.

After I added the edited jar back into the .zip, I emidiatly deleted the jar on my local disk, BEFORE $zip->close() ; the close() obviously didn't work, so, the changes weren't saved.

What did we learn?

close() BEFORE you delete/... any files!

any questions? lol You should put your solution as a reply and accept it. at least it would be looking like a "normal" questiondynamic