1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
//URL où se trouve le fichier
define('URL', 'http://ww.exemple.com/');
//Répertoire et Fichier d'entree
define('ENTREE', './upload/testinit.txt');
//Fichier de sortie
define('SORTIE', './upload/test.txt');
// On recherche la date de modification des deux fichiers pour savoir lequel est le plus récent.
$datelocal = date('Ymd',filemtime(SORTIE));
$datedistant = date('Ymd',filemtime(ENTREE));
//Si le fichier à importer est plus rcent, on réalise l'import
if ($datedistant >= $datelocal) {
//Initialisation CURL et Ouverture du fichier
$ch = curl_init(URL);
$fp = fopen(SORTIE, 'w') or die('Ouverture du fichier impossible en écriture');
$file = fopen(ENTREE, 'r') or die('Ouverture du fichier impossible en lecture');
//Définition des options CURL
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_UPLOAD, TRUE);
curl_setopt($ch, CURLOPT_INFILE, $file);
//Execution CURL et Fermeture des connexions
curl_exec($ch) or die('Erreur Curl : 'curl_error($ch));
curl_close($ch);
fclose($fp);
fclose($file);
echo 'Ok';
} else {
echo 'Pas de nouveau fichier';
} |
Partager