How to create zip file without path?

Hello,

I have generated a PHP script that creates files needed for EPUB file.

I have a temp directory where these files are created into and then needs to be zipped. The directory structure is:

mimetype
content.opf
index.html
stylesheet.css
toc.ncx
META-INF
META-INF/container.xml

I use the following commands to create the EPUB file:

system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx $myDir/META-INF $myDir/META-INF/container.xml") ;

The problem is the the "j" option removes the path from all files, but I need the zip file to have all these files in the root of the zip except the META-INF directory and its file containes.xml must be at the root of the zip file.

So how can I create a zip file containing just these files and that one directory without the full path?

Thanks for your help!

Specifying $myDir/META-INF and $myDir/META-INF $myDir/META-INF/container.xml both with the -r flag is redundant, as with -r it will traverse the directory tree and add everything inside.

You could call zip one more time, without the -j flag, to add that directory:

system ("zip -q0Xj $zipFile mimetype") ;
system ("zip -qXr9Dj $zipFile $myDir/mimetype $myDir/content.opf $myDir/index.html $myDir/stylesheet.css $myDir/toc.ncx");
system("zip -qXr9D $zipFile $myDir/META-INF");

This won't work as $myDir is in a form of "/var/www/customers/myaccount" so also this path will be included into the zip file.

So what I need is create a ZIP file of a remote diretory's contents so that also the META-INF folder will be included into the zip file but the parent folder structure is omitted.

you could try to cd into $myDir before zipping.
as per man pages:

but this might vary depending on the system of course.

Personally, I doubt it. It's not like tar, where each platform rolls their own; zip is usually just info-zip everywhere you go. And it does go nearly everywhere.