WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

here is what i have so far.

  function zip_gallery()
      global $post;
      $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', ));

      if ($images) {
          $save = $post->post_title;

          $zip = new ZipArchive;
          if ($zip->open($save . '.zip', ZIPARCHIVE::CREATE) === true) {
              foreach ($images as $image) {
                  $file = wp_get_attachment_url($image->ID, 'full', false, false);
                  $filename = pathinfo($file);
                  $zip->addFile($file, $filename);


can someone shed some light on what im doing wrong.

share|improve this question
Did you manage to do this? – user3047 Sep 19 '11 at 21:43
up vote 6 down vote accepted

ZipArchive->addFile() method expects local path to file, while wp_get_attachment_url() returns URL. You need to build local path for file from URL or in other way.

share|improve this answer
is there a plugin which does this? – user3047 Sep 19 '11 at 21:55
@user3047 not that I know, but I hadn't looked... – Rarst Sep 20 '11 at 8:10
Did you manage to make it work? This way? – user3047 Sep 20 '11 at 16:01
@user3047 I merely pointed out obvious error in code back then, I had not tried to implement and test this. – Rarst Sep 20 '11 at 17:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.