zip_add_file

This function is used to add a file into a ZIP file created with zip_create.

If the call is successful, the function will return 0, otherwise it will throw a fatal error.

The src file is only loaded when zip_save is called later, so an invalid file will not throw an error during this call.

NOTE This functionality is not available for the HTML5 target platform.

 

Syntax:

zip_add_file(zip_object, dest, src);

ArgumentTypeDescription
zip_objectZIP FileA ZIP file created with zip_create
destStringThe destination file name to be created in the ZIP. Can include directories.
srcStringThe source file to be placed into the ZIP

 

Returns:

Real

 

Example:

var _zip = zip_create();

zip_add_file(_zip, "new.txt", "new.txt");
zip_add_file(_zip, "sounds/snd_attack_arc_01.wav", "snd_attack_arc_01.wav");

zip_save(_zip, "upload.zip");

This creates a new ZIP file, adds two files to it (with the second file in a subdirectory called sounds/) and then saves the ZIP to disk as upload.zip.