Close #11; Download en js via 'ModuleRequest' fonctionnel passage par 2 fichiers temporaires (1: le script qui lance le téléchargement et affiche le contenu de l'autre; 2: Le contenu du fichier)

This commit is contained in:
xdrm-brackets 2016-05-19 14:17:53 +02:00
parent 2373d2c5bc
commit 7083a7a9dc
8 changed files with 21 additions and 20 deletions

View File

@ -86,15 +86,16 @@
// //
// } // }
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$req = new ModuleRequest('download/phone', array('subjects'=>array(273))); $req = new ModuleRequest('download/phone', array('subjects'=>array(1, 273, 341)));
$res = $req->download(); $res = $req->download();
if( $res->error != ManagerError::Success ) if( $res->error != ManagerError::Success )
var_dump( ManagerError::explicit($res->error) ); var_dump( ManagerError::explicit($res->error) );
var_dump($res);
/* [4] Analyse des performances de `lightdb` /* [4] Analyse des performances de `lightdb`
=========================================================*/ =========================================================*/
// $start = microtime(true); // $start = microtime(true);

View File

@ -1,7 +0,0 @@
<?php
unlink( __FILE__ );
?>

View File

@ -199,6 +199,7 @@
=========================================================*/ =========================================================*/
if( $fromAjax ){ if( $fromAjax ){
$tmpfname = '/tmp/download_'.uniqid().'.php'; $tmpfname = '/tmp/download_'.uniqid().'.php';
/* (1) On crée le fichier temporaire */ /* (1) On crée le fichier temporaire */
@ -212,13 +213,17 @@
fwrite($tmpfile, "header(\"$header: $value\");".PHP_EOL); fwrite($tmpfile, "header(\"$header: $value\");".PHP_EOL);
/* (3) Script qui écrira le contenu */ /* (3) Script qui écrira le contenu */
$bodyWithoutQuotes = str_replace("'", "\\'", utf8_decode($returned['body']) ); // 1) On écrit le contenu dans un fichier temporaire (et oui encore)
fwrite($tmpfile, "echo <<< EOF".PHP_EOL); $bodyfname = __ROOT__.'/tmp/content_'.uniqid().'.php';
fwrite($tmpfile, $bodyWithoutQuotes.PHP_EOL); $bodyfile = fopen($bodyfname, 'w');
fwrite($tmpfile, "EOF;".PHP_EOL); fwrite($bodyfile, $returned['body']);
fclose($bodyfile);
/* (4) Script qui supprimera le fichier */ fwrite($tmpfile, "readfile('$bodyfname');".PHP_EOL);
fwrite($tmpfile, 'unlink(__FILE__);'.PHP_EOL);
/* (4) Script qui supprimera les fichiers temporaires */
fwrite($tmpfile, "unlink('$bodyfname');".PHP_EOL);
fwrite($tmpfile, "unlink(__FILE__);".PHP_EOL);
fwrite($tmpfile, '?>'.PHP_EOL); fwrite($tmpfile, '?>'.PHP_EOL);

View File

@ -1 +1 @@
272 408

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"1":{"line":0,"hash":"423bda798fbf4363a61d945e936c6a11ce9ac057"},"69":{"line":1,"hash":"785691cf7be9f8b18eb1a298db3187bdc86c4884"},"137":{"line":2,"hash":"47fc53f817eded81eecd15b2e042722d52bd8513"},"205":{"line":3,"hash":"0a296a89a05509be912fefda7fdcc2692a244208"}} {"1":{"line":0,"hash":"423bda798fbf4363a61d945e936c6a11ce9ac057"},"69":{"line":1,"hash":"785691cf7be9f8b18eb1a298db3187bdc86c4884"},"137":{"line":2,"hash":"47fc53f817eded81eecd15b2e042722d52bd8513"},"205":{"line":3,"hash":"0a296a89a05509be912fefda7fdcc2692a244208"},"273":{"line":4,"hash":"1b9c3317ae25f49f6cfdee6aa34fcbc381c3a7a7"},"341":{"line":5,"hash":"8857d8b1c8e7fbcb455847bdf3c9fd34e34ef217"}}

2
view/js/data-min.js vendored
View File

@ -1 +1 @@
var exportDeflater=new FormDeflater(document.getElementById("export-form"),["input"],["data-name"]);$("#export-form #export-all").addEventListener("click",function(b){"1"==exportDeflater.deflate().phone&&api.send({path:"download/phone",subjects:[1,137]},function(a){if(0!=a.ModuleError)return!1;document.location=a.link})},!1); var exportDeflater=new FormDeflater(document.getElementById("export-form"),["input"],["data-name"]);$("#export-form #export-all").addEventListener("click",function(b){"1"==exportDeflater.deflate().phone&&api.send({path:"download/phone",subjects:[341]},function(a){if(0!=a.ModuleError)return!1;document.location=a.link})},!1);

View File

@ -16,7 +16,7 @@ $('#export-form #export-all').addEventListener('click', function(e){
/* (1) Si téléchargement de données cellulaires */ /* (1) Si téléchargement de données cellulaires */
if( deflated.phone == '1' ){ if( deflated.phone == '1' ){
api.send({ 'path': 'download/phone', 'subjects': [1, 137] }, function(res){ api.send({ 'path': 'download/phone', 'subjects': [341] }, function(res){
// Si erreur // Si erreur
if( res.ModuleError != 0 ) if( res.ModuleError != 0 )