Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

zip file of images in a post WordPress

  • SOLVED

here is the code so far. any ideas on making it work?


// plugin file

add_action('init','zipgallery_js');

function zipgallery_js() {
wp_enqueue_script('jquery');
wp_register_script('zip_gallery', plugin_dir_url(__FILE__) . 'download.js', array('jquery'), '1.0');
wp_enqueue_script('zip_gallery');
}

function createzip() {
global $post;
$images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', ));
$zipname = 'zips/' . $_POST['rand'];
$zip = new ZipArchive;
if ($images) {
if ($zip->open($zipname . '.zip', ZIPARCHIVE::CREATE) === TRUE) {
foreach ($images as $image) {
$file = get_attached_file($image->ID, false);
$filename = basename($file);
$zip->addFile($file, $filename);
}

}
$zip->close();
}
}

function zipgallery_shortcode() {
return '<a id="download" href="#">Download</a>';
}

add_shortcode('zipgallery','zipgallery_shortcode');

// download.js

var rand = Math.floor(Math.random()*9999999999);

jQuery(document).ready(function(){
jQuery('#download').attr('href', '/wp-content/plugins/zipgallery/zips/' + rand + '.zip');
jQuery('#download').hover(function(e){
$.ajax({
url: "http://90mb.com/wp-content/plugins/zipgallery/dl.php",
type: "POST",
dataType: "html",
data: "&rand=" + rand,
success: function(html) {
jQuery('#download').show();
jQuery('#download').attr('href', '/wp-content/plugins/zipgallery/zips/' + rand + '.zip');

}
});
});
});


// dl.php

require_once('../../../wp-load.php');

if($_SERVER['REQUEST_METHOD'] == "POST") {
echo createzip();
break;
}

else {
echo "No direct file access allowed";
}




thanks.

Answers (2)

2011-02-03

Oleg Butuzov answers:

any example on a live server?
its also can me a server issue.


Oleg Butuzov comments:

P/S/
What the sense in creating zip every time insted creating just one file? you are ddosing yourself.

make the zip in shortcode generation. and check if there any new file - generte new zip, if not - here you have old zip. so easy...

2011-02-03

Chris Lee answers:

I would just use nextgen gallery. you can just drag and drop a zip file and it'll upload the whole batch

http://wordpress.org/extend/plugins/nextgen-gallery/

Then you can link to the zip file: http://wordpress.org/support/topic/plugin-nextgen-gallery-link-to-original-zip-file


chrismccoy comments:

i would rather not use nextgen, im looking to do this on the fly from a current post.