[api.core.Request] if DOWNLOAD -> create TMP dir in PUBLIC
This commit is contained in:
parent
6273a58046
commit
be1e5b0a4d
|
@ -614,39 +614,44 @@ use \error\core\Error;
|
||||||
|
|
||||||
/* (3) Gestion du téléchargement différé (AJAX)
|
/* (3) Gestion du téléchargement différé (AJAX)
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) On génère les noms de fichiers utiles */
|
/* (1) Create if not exists public_html/tmp */
|
||||||
|
if( !is_dir(__PUBLIC__.'/tmp') ){
|
||||||
|
mkdir(__PUBLIC__.'/tmp');
|
||||||
|
chmod(__PUBLIC__.'/tmp', 0775);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (2) On génère les noms de fichiers utiles */
|
||||||
$target_fname = '/tmp/download_'.uniqid().'.php'; // cible
|
$target_fname = '/tmp/download_'.uniqid().'.php'; // cible
|
||||||
$buffer_fname = __ROOT__.'/tmp/content_'.uniqid().'.php'; // buffer
|
$buffer_fname = __ROOT__.'/tmp/content_'.uniqid().'.php'; // buffer
|
||||||
|
|
||||||
/* (2) On écrit le BODY dans un fichier buffer */
|
/* (3) On écrit le BODY dans un fichier buffer */
|
||||||
$buffer_file = fopen($buffer_fname, 'w');
|
$buffer_file = fopen($buffer_fname, 'w');
|
||||||
fwrite($buffer_file, $returned['body']);
|
fwrite($buffer_file, $returned['body']);
|
||||||
fclose($buffer_file);
|
fclose($buffer_file);
|
||||||
|
|
||||||
/* (3) On crée le fichier cible */
|
/* (4) On crée le fichier cible */
|
||||||
$target_fnameroot = __PUBLIC__.$target_fname;
|
$target_fnameroot = __PUBLIC__.$target_fname;
|
||||||
$taret_file = fopen($target_fnameroot, 'w');
|
$taret_file = fopen($target_fnameroot, 'w');
|
||||||
fwrite($taret_file, '<?php'.PHP_EOL);
|
fwrite($taret_file, '<?php'.PHP_EOL);
|
||||||
|
|
||||||
|
/* (5) Script qui écrira les headers */
|
||||||
/* (4) Script qui écrira les headers */
|
|
||||||
foreach($returned['headers'] as $header=>$value)
|
foreach($returned['headers'] as $header=>$value)
|
||||||
fwrite($taret_file, "header(\"$header: $value\");".PHP_EOL);
|
fwrite($taret_file, "header(\"$header: $value\");".PHP_EOL);
|
||||||
|
|
||||||
/* (5) Script qui écrira le contenu du buffer */
|
/* (6) Script qui écrira le contenu du buffer */
|
||||||
chmod($buffer_fname, 0775);
|
chmod($buffer_fname, 0775);
|
||||||
fwrite($taret_file, "readfile('$buffer_fname');".PHP_EOL);
|
fwrite($taret_file, "readfile('$buffer_fname');".PHP_EOL);
|
||||||
|
|
||||||
/* (6) Script qui supprimera les fichiers: buffer+target */
|
/* (7) Script qui supprimera les fichiers: buffer+target */
|
||||||
fwrite($taret_file, "unlink('$buffer_fname');".PHP_EOL);
|
fwrite($taret_file, "unlink('$buffer_fname');".PHP_EOL);
|
||||||
fwrite($taret_file, "unlink(__FILE__);".PHP_EOL);
|
fwrite($taret_file, "unlink(__FILE__);".PHP_EOL);
|
||||||
fwrite($taret_file, '?>'.PHP_EOL);
|
fwrite($taret_file, '?>'.PHP_EOL);
|
||||||
|
|
||||||
/* (7) On ferme le fichier cible */
|
/* (8) On ferme le fichier cible */
|
||||||
fclose($taret_file);
|
fclose($taret_file);
|
||||||
chmod($target_fnameroot, 0775);
|
chmod($target_fnameroot, 0775);
|
||||||
|
|
||||||
/* (8) On envoie la réponse contenant le lien du fichier cible */
|
/* (9) On envoie la réponse contenant le lien du fichier cible */
|
||||||
$response = new Response($this->error);
|
$response = new Response($this->error);
|
||||||
$response->append('link', $target_fname);
|
$response->append('link', $target_fname);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue