When a user clicks download it will successfully create a zip on server with the files, then it should alert the the zips location (variable $zip) from php as a response but instead it is alerting [object Object]. Everything else is working how it should. What am I doing wrong?
JQuery:
$('.download').click(function() {
window.keys = [];
$('.pad').each(function(i, obj) {
var key = $(this).attr('key');
keys.push(key)
});
var jsonString = JSON.stringify(keys);
$.ajax({
type:'post',
url:'download.php',
data: {data : jsonString},
cache: false,
dataType: 'json',
success: function(data){
alert(data);
}
});
});
PHP:
<?php
$data = json_decode(stripslashes($_POST['data']));
$numbercode = md5(microtime());
$zip = new ZipArchive();
$zip->open('kits/'.$numbercode.'.zip', ZipArchive::CREATE);
foreach($data as $d) {
$zip->addFile($d);
}
$zip->close();
echo json_encode($zip);
?>