Eléphant du PHP |
168 Messages
07 janv. 2010, 15:46
Je te montre mon code mais l'algo est basique donc au niveau de l'optimisation je vois pas trop ce que tu pourrais faire. Mais bon...
EDIT: petite erreur de ma part: dernière boucle while fausse et inutile!
P.S: j'ai commenté certaine parties mais c'est pour des tests.
<?php
require("zip.lib.php") ;
$date2 = getdate();
$jour = $date2['mday'];
$date = $date2['year'].'-'.$date2['mon'].'-'.$jour;
/*$host = 'db2031.1and1.fr';
$user = "dbo293777976";
$password = "bonjour";
$bdd = "db293777976";
mysql_connect($host, $user, $password) or die ("Connexion au serveur impossible");
mysql_select_db($bdd) or die ("Connexion a la base impossible");
$requete ="select * from biens";
$exec = mysql_query($requete) or die("erreur dans ma requête");*/
$ftp_server = "vidati.com";
$ftp_user_name="u45023319";
$ftp_user_pass="7nYV72jU";
$conn_id = ftp_connect($ftp_server);
$chemin = "c:\\xml\\".$_POST['fichier'];
// Authentification avec nom de compte et mot de passe
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass");
if($login_result) echo "connecté"; else echo "pas connecté";
if(ftp_get($conn_id, $chemin, $_POST['fichier'], FTP_BINARY))
{
$compte =0;
$monZip = $_POST['fichier'];
$zip = new ZipArchive;
if ($zip->open($monZip) === TRUE) {
$zip->extractTo('c:/xml/');
$zip->close();
} else {
echo 'échec, impossible de lire votre archive';
}
$doss = dir('c:\\xml\\');
while ($entry = $doss->read()) {
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if($ext == "xml" ||strtolower($ext) == "xml")
{
$path_parts = pathinfo($entry);
$monXml = $path_parts['filename'].'.'.$ext;
break;
}
else
$monXml = "";
}
$doss = dir('xml\\');
ftp_chdir($conn_id,"immobilieretcredit.com/Util/2");
/*while ($entry = $doss->read()) {
$nom = pathinfo($entry, PATHINFO_FILENAME);
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if($ext == "jpg" ||strtolower($ext) == "jpg")
{
ftp_put($conn_id, $nom, $entry, FTP_BINARY));
}
}*/
// Peut être une url ou un chemin relatif
$url_fichier_xml= 'xml\\'.$monXml;
$xml=simplexml_load_file($url_fichier_xml);
foreach($xml->BIEN as $bien) {
// On boucle sur chaque bien...
/*$existe = 0;
if($xml->TYPE_OFFRE) $typeoffre = $xml->TYPE_OFFRE; else $typeoffre = 20;
if($xml->NO_DOSSIER) $numdossier = $xml->NO_DOSSIER; else $numdossier = 0;
if($xml->DATE_OFFRE) $dateoffre = $xml->DATE_OFFRE; else $dateoffre = $date;
if($xml->PRIX) $prix=$xml->PRIX; else $prix = 0;
if($xml->CP_OFFRE) $cp = $xml->CP_OFFRE; else $cp=0;
if($xml->VILLE_OFFRE) $ville = $xml->VILLE_OFFRE; else $ville = "";
if($xml->QUARTIER) $quartier=$xml->QUARTIER; else $quartier="";
if($xml->CATEGORIE) $titre = $xml->CATEGORIE; else $titre = "";
if($xml->NB_PIECES) $pieces = $xml->NB_PIECES; else $pieces = 0;
if($xml->NB_CHAMBRES)$chambres = $xml->NB_CHAMBRES; else $chambres = 0;
if($xml->SURF_HAB) $surf = $xml->SURF_HAB; else $surf = 0;
if($xml->SURF_TERRAIN) $surfT = $xml->SURF_TERRAIN; else $surfT = 0;
if($xml->NB_ETAGES) $nbetage = $xml->NB_ETAGES;
if($xml->ANNEE_CONS) $annee = $xml->ANNEE_CONS;
if($xml->CUISINE) $cuisine = $xml->CUISINE;
if($xml->TEXTE_FR) $texte = $xml->TEXTE_FR; else $texte="Pas de description, contactez vidati";
if(substr($cp,0,2 == '75') && $quartier !="")
{
$req = "select LOCAL_ID from localisation where LOCAL_VILLE = 'PARIS' and LOCAL_QUARTIER = '$quartier'";
$exec = mysql_query($req) or die ("erreur dans ma requête($req)");
$exec2 = mysql_fetch_object($exec);
if(mysql_num_rows($exec)== 1) $cpid = $exec2->LOCAL_ID;
else
{
$req = "select LOCAL_ID from localisation where LOCAL_CP = '$cp' and LOCAL_QUARTIER = ''";
$exec = mysql_fetch_object(mysql_query($req));
$cpid = $exec->LOCAL_ID;
}
}
else
{
$req = "select LOCAL_ID from localisation where LOCAL_CP = '$cp' and LOCAL_QUARTIER = ''";
$exec = mysql_fetch_object(mysql_query($req));
$cpid = $exec->LOCAL_ID;
}
while($entre = mysql_fetch_array($listebiens))
{
if($entre['BIEN_NUM_ASP'] == $bien->NO_ASP)
{
//requete update
$existe = 1;
}
}
if($existe==0)
{
//requête insert;
}
$requete ="select * from biens";
$listebiens = mysql_query($requete) or die("erreur dans ma requête");
*/
}
$doss = dir('c:\\xml\\');
while ($entry = $doss->read())
{
$nom = pathinfo($entry, PATHINFO_FILENAME);
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if($ext == "jpg" ||strtolower($ext) == "jpg")
{
$path_parts = pathinfo($entry);
ftp_get($conn_id, $nom, $nom, FTP_BINARY);
}
}
}
else echo 'fichier introuvable';
?>