Remove depencies of library/common/curl : getUrl
This commit is contained in:
parent
ad2984ee91
commit
c8e2258ae2
@ -5,7 +5,7 @@ class Iris
|
||||
protected $pathIrisPdf;
|
||||
protected $codeCommune;
|
||||
protected $erreur = '';
|
||||
|
||||
|
||||
public function __construct($codeCommune)
|
||||
{
|
||||
require_once 'common/curl.php';
|
||||
@ -13,7 +13,7 @@ class Iris
|
||||
$this->pathIrisPdf = realpath($c->profil->path->data).'/iris';
|
||||
$this->codeCommune = $codeCommune;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Récupére l'avis de situtation à partir du site au format pdf
|
||||
* @param string $format Format 'pdf' ou 'array'
|
||||
@ -35,28 +35,25 @@ class Iris
|
||||
else
|
||||
{
|
||||
$url = 'http://www.insee.fr/fr/methodes/zonages/iris/cartes/carte_iris_'.$this->codeCommune.'.pdf';
|
||||
$referer = $cookie = '';
|
||||
$page = getUrl($url, $cookie, '', $referer, false, 'www.insee.fr', '', $this->timeout);
|
||||
//Code en 4xx ou 5xx signifie une erreur du serveur
|
||||
$codeN = floor($page['code']/100);
|
||||
if($codeN==4 || $codeN==5 || substr($page['body'],0,4)!='%PDF')
|
||||
{
|
||||
$this->erreur = "Fichier introuvable à l'insee !";
|
||||
try {
|
||||
$client = new Zend_Http_Client($url);
|
||||
$client->setStream();
|
||||
$response = $client->request('GET');
|
||||
if ($response->isSuccessful() && substr($response->getBody(),0,4)=='%PDF') {
|
||||
copy($response->getStreamName(), $fichier);
|
||||
} else {
|
||||
$this->erreur = "Fichier introuvable à l'insee !";
|
||||
return false;
|
||||
}
|
||||
} catch (Zend_Http_Client_Exception $e) {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fp = fopen($fichier, "w");
|
||||
fwrite($fp, $page['body']);
|
||||
fclose($fp);
|
||||
return $page['body'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function erreur()
|
||||
{
|
||||
return $this->erreur;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user