From 90065bafc4960502e8c8539a6c192ea677986154 Mon Sep 17 00:00:00 2001 From: Cabillot Julien Date: Thu, 27 Nov 2014 13:31:29 +0100 Subject: [PATCH] passage par un rep temporaire --- {download => downloaded}/.gitignore | 0 downloading/.gitignore | 2 ++ include/config.php | 9 +++++++-- lib/Download.php | 17 ++++++++++++----- 4 files changed, 21 insertions(+), 7 deletions(-) rename {download => downloaded}/.gitignore (100%) create mode 100644 downloading/.gitignore diff --git a/download/.gitignore b/downloaded/.gitignore similarity index 100% rename from download/.gitignore rename to downloaded/.gitignore diff --git a/downloading/.gitignore b/downloading/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/downloading/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/include/config.php b/include/config.php index c4cde81..cee9700 100644 --- a/include/config.php +++ b/include/config.php @@ -8,11 +8,16 @@ define('DB_COLL', 'mydl'); /** * Defini le repertoire temporaire ou seront stocke les downloads */ -define('DOWNLOADDIR', dirname(__FILE__).'/../download'); +define('DOWNLOADINGDIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'downloading'); +/** + * Defini le repertoire definitif ou seront stocke les downloads + */ +define('DOWNLOADEDDIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'downloaded'); + /** * Defini l'endroit ou se trouve le lock pour les download */ -define('DOWNLOADLOCK', dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'download'.DIRECTORY_SEPARATOR.'lock'); +define('DOWNLOADLOCK', DOWNLOADINGDIR.DIRECTORY_SEPARATOR.'lock'); include dirname(__FILE__).'/../lib/DbMongo.php'; include dirname(__FILE__).'/../lib/Download.php'; diff --git a/lib/Download.php b/lib/Download.php index 0a4e008..0ea1ad6 100644 --- a/lib/Download.php +++ b/lib/Download.php @@ -77,7 +77,6 @@ class Download { ['_id' => $this->_id], ['$push' => ['event' => $event]] ); -file_put_contents('toto', print_r($dbRet, true)); } /** @@ -86,9 +85,15 @@ file_put_contents('toto', print_r($dbRet, true)); * @return array Informations sur le transfert */ public function get() { - // TODO : utiliser un nom de fichier temporaire - set_time_limit(0); - $fp = fopen(DOWNLOADDIR.DIRECTORY_SEPARATOR.$this->filename, 'w+'); + // TODO : tester si fichier existant (temp et definitif) + set_time_limit(0); + + if (file_exists(DOWNLOADINGDIR.DIRECTORY_SEPARATOR.$this->filename) || file_exists(DOWNLOADEDDIR.DIRECTORY_SEPARATOR.$this->filename)) { + echo 'le fichier existe deja, exit'; + exit(); + } + + $fp = fopen(DOWNLOADINGDIR.DIRECTORY_SEPARATOR.$this->filename, 'w+'); $ch = curl_init($this->premURL); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @@ -96,7 +101,9 @@ file_put_contents('toto', print_r($dbRet, true)); curl_exec($ch); $retour = curl_getinfo($ch); curl_close($ch); - fclose($fp); + fclose($fp); + + rename(DOWNLOADINGDIR.DIRECTORY_SEPARATOR.$this->filename, DOWNLOADEDDIR.DIRECTORY_SEPARATOR.$this->filename); // TODO : verifier le retour ? $this->addEvent([