Title: Automatically zip content
Last modified: August 21, 2016

---

# Automatically zip content

 *  [valentin_caen](https://wordpress.org/support/users/valentin_caen/)
 * (@valentin_caen)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/automatically-zip-content/)
 * Hi,
 * I’m working on an artist site, who needs a press kit.
 * I’ll use advanced custom fields to let him upload some photos, logos, and pdf.
 * That i want is when he upload a new file a script create automatically an updated
   zip file of his press kit.
 * Do you know a plugin or a php script that can help me to do this ?
 * Thanks,
 * Valentin

Viewing 1 replies (of 1 total)

 *  Thread Starter [valentin_caen](https://wordpress.org/support/users/valentin_caen/)
 * (@valentin_caen)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/automatically-zip-content/#post-4331933)
 * So, finally I did it simply with a little bit of PHP
 * I past my code here if someone needs to do something similar 😉
 *     ```
       <?php
       	$file = get_field('file'); // Get files from Advanced custom fields
       	$name_of_zip = get_field('name_of_zip'); // Get name of zip from Advanced custom fields
   
       	$current_path = getcwd(); // get the current path to where the file is located
       	$folder = explode("/", $current_path); // divide the path in parts (aka folders)
       	$blog = $folder[8]; // the blog's folder is the number 8 on the path
       	$root = realpath($_SERVER["DOCUMENT_ROOT"]); // $root = path without the blog installation folder.
       	$path = "$root/$blog"; //Get the path of the blog
   
       	$url = get_home_url()."/"; // Get the blog url plus /
       	$files_to_zip = str_replace($url, $path, $file['url']);// Convert files url to files path 
   
       	$zip = new ZipArchive();
       	$filename = $path."wp-content/uploads/press-kit/".$name_of_zip.".zip"; // Create the zip in wp-content/uploads/press-kit
       	$new_filename = substr($files_to_zip,strrpos($files_to_zip,'/') + 1); // Delete path for the zip
   
       	$zip->open($filename, ZipArchive::CREATE);
       	$zip->addFile($files_to_zip, $new_filename);
   
       	$zip->close();
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Automatically zip content’ is closed to new replies.

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [folder](https://wordpress.org/support/topic-tag/folder/)
 * [zip](https://wordpress.org/support/topic-tag/zip/)

 * 1 reply
 * 1 participant
 * Last reply from: [valentin_caen](https://wordpress.org/support/users/valentin_caen/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/automatically-zip-content/#post-4331933)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
