Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Piaui

Alguem já utilizou o JSZip ?

Recommended Posts

CONSEGUIR ESSE EXEMPLO AQUI NELE TEM SELECIONAR OS ARQUIVOS COM UM FORMULÁRIO. QUERIA QUE NÃO PRECISA-SE.


TENTEI SUBSTITUIR O CHECKBOX POR HIDDEN NÃO FUNCIONOU.


ESTOU LISTANDO OS ARQUIVOS USANDO ID DA URL.




<?php require_once('Connections/teste.php'); ?>
<?php
// Load the tNG classes
require_once('includes/tng/tNG.inc.php');


// Make unified connection variable
$conn_teste = new KT_connection($teste, $database_teste);


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;


$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);


switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}


$colname_down1 = "-1";
if (isset($_GET['video])) {
$colname_down1 = $_GET['video'];
}
mysql_select_db($database_teste, $teste);
$query_down1 = sprintf("SELECT * FROM video WHERE id = %s", GetSQLValueString($colname_down1, "int"));
$down1 = mysql_query($query_down1, $teste) or die(mysql_error());
$row_down1 = mysql_fetch_assoc($down1);
$totalRows_down1 = mysql_num_rows($down1);


// Begin File List Recordset
$listFolder_Recordset1 = new tNG_FileListRecordset("", $conn_teste);
$listFolder_Recordset1->setBaseFolder("video/");
$listFolder_Recordset1->setFolder("{down1.id}");
$listFolder_Recordset1->setOrder("name", "ASC");
$listFolder_Recordset1->setAllowedExtensions("avi");
// Create the fake recordset
$Recordset1 = $listFolder_Recordset1->Execute();
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = $listFolder_Recordset1->RecordCount();
// End File List Recordset
?>
<link rel="stylesheet" href="https://stuk.github.io/jszip/documentation/css/main.css">


<script type="text/javascript" src="https://stuk.github.io/jszip/dist/jszip.js"></script>


<script type="text/javascript" src="//stuk.github.io/jszip-utils/dist/jszip-utils.js"></script>

<script type="text/javascript" src="https://stuk.github.io/jszip/test/jquery-1.8.3.min.js"></script>


<script type="text/javascript" src="https://stuk.github.io/jszip/vendor/FileSaver.js"></script>

<form action="#" id="download_form">


<?php do { ?>
<input type="checkbox" checked data-url="video/<?php echo $row_down1['id']; ?>/<?php echo $row_Recordset1['name']; ?>" />
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>






<button type="submit" class="btn btn-primary">BAIXAR</button>
</form>


<p class="hide" id="result"></p>




</div>

<script type="text/javascript" src="testes/downloader.js"></script>

</body>
</html><?php
mysql_free_result($down1);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites
TAMBEM ENCONTREI ESSE SCRIPT MAIS ESTÁ DANDO ERROR NO CONSOLE NA ULTIMAS LINHA:


Uncaught SyntaxError: Unexpected end of input




<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width">





<title>ZIP</title>

</head>

<body>

<button id='download_zip'>Zip</button>

<script type="text/javascript">

$(document).ready(function(){

$('#download_zip').on('click', download_zip);

});

function deferredAddZip(url, filename, zip) {

var deferred = $.Deferred();

JSZipUtils.getBinaryContent(url, function (err, data) {

if(err) {

deferred.reject(err);

} else {

zip.file(filename, data, {binary:true});

deferred.resolve(data);

}

});

return deferred;

}

function download_zip() {

// INPUT DATA

var project_name = "some_project_name";

var file_lists = [



'https://bropro-staging.s3.amazonaws.com/uploads/music/file/56fa7a928523c38fa613d3a6/DJ_BAUR_-_Deep_N_Love_Mix_-_Track_01.mp3'

];

var zip = new JSZip();

var deferreds = [];

for(var i in file_lists) {

url = file_lists;

filename = url.substring(url.lastIndexOf('/')+1);

deferreds.push(deferredAddZip(url, filename, zip));

}

// when everything has been downloaded, we can trigger the dl

$.when.apply($, deferreds).done(function () {

var blob = zip.generate({type:"blob"});

saveAs(blob, project_name+".zip");

console.log("done !");

}).fail(function (err) {

console.log(err);

});

</script>

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.