4

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);
              }

              $zip->close();
          }
      }
  }

can someone shed some light on what im doing wrong.

1
  • Did you manage to do this?
    – user3047
    Sep 19, 2011 at 21:43

1 Answer 1

6

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.

4
  • is there a plugin which does this?
    – user3047
    Sep 19, 2011 at 21:55
  • @user3047 not that I know, but I hadn't looked...
    – Rarst
    Sep 20, 2011 at 8:10
  • Did you manage to make it work? This way?
    – user3047
    Sep 20, 2011 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, 2011 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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