ZipArchive - addFile won't work

冷暖自知 提交于 2019-12-11 03:47:03

问题


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!

来源:https://stackoverflow.com/questions/6289456/ziparchive-addfile-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!