Creare un file ZIP con le immagini da un post WordPress

3 feb 2011, 00:08:23
Visualizzazioni: 1.35K
Voti: 4

Ecco quello che ho fatto finora.

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

Qualcuno può spiegarmi cosa sto sbagliando?

1
Commenti

Sei riuscito a farlo?

user3047 user3047
20 set 2011 00:43:45
Tutte le risposte alla domanda 1
4

Il metodo ZipArchive->addFile() si aspetta un percorso locale del file, mentre wp_get_attachment_url() restituisce un URL. È necessario costruire il percorso locale per il file dall'URL o in altro modo.

3 feb 2011 09:09:21
Commenti

esiste un plugin che fa questo?

user3047 user3047
20 set 2011 00:55:36

@user3047 non che io sappia, ma non ho cercato...

Rarst Rarst
20 set 2011 11:10:32

Sei riuscito a farlo funzionare? In questo modo?

user3047 user3047
20 set 2011 19:01:10

@user3047 Ho solo fatto notare un evidente errore nel codice in quel momento, non avevo provato a implementarlo e testarlo.

Rarst Rarst
20 set 2011 20:59:37