Bonjour,
J'ai un site hébergé chez OVH dans lequel j'ai crée un fichier php afin de réaliser une passerelle entre mon logiciel de transaction et le site.
lorsque je lance le fichier, le processus rapatrie un certain nombre d'enregistrement puis plante (jamais au même endroit).
J'ai le même site en local et là tout fonctionne normalement.
Pouvez vous me dire si j'ai commis un erreur ou si le problème viens d'OVH.
Merci d'être indulgent sur la programmation, je suis débutant.
<?php
set_time_limit(0);
ini_set('max_execution_time',0);
$LISTEPA = simplexml_load_file('http://xxx');
$user = 'xxx';
$passwd = 'xxx';
$host = 'xxx';
$bdd = 'xxx';
$db = mysql_connect($host,$user,$passwd);
mysql_select_db($bdd,$db);
$req = "TRUNCATE TABLE xxx";
mysql_query($req) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
$a_del = "./images/com_jea/images/"; // <- c'est ici qu'on remplace
clearDir($a_del);
function clearDir($dossier) {
$ouverture=@opendir($dossier);
if (!$ouverture) return;
while($fichier=readdir($ouverture)) {
if ($fichier == '.' || $fichier == '..') continue;
if (is_dir($dossier."/".$fichier)) {
$r=clearDir($dossier."/".$fichier);
if (!$r) return false;
}
else {
$r=@unlink($dossier."/".$fichier);
if (!$r) return false;
}
}
closedir($ouverture);
$r=@rmdir($dossier);
@rename($dossier,"trash");
return true;
}
$id = 1;
foreach ($LISTEPA->BIEN as $BIEN) {
$land_space = 0;
/* import biens en vente*/
if ($BIEN->VENTE) {
$is_renting = 0;
foreach ($BIEN->VENTE as $VENTE) {
$charges = "$VENTE->CHARGES_MENSUELLE";
$ref = "$VENTE->NUM_MANDAT";
$prix = "$VENTE->PRIX";
print "Réference : {$ref} <br />\n";
print "titre : {$prix} <br />\n";
print "id : {$id} <br />\n";
}
}
if ($BIEN->LOCATION) {
$is_renting = 1;
foreach ($BIEN->LOCATION as $LOCATION) {
$charges = "$LOCATION->CHARGES";
$ref = "$LOCATION->NUM_MANDAT";
$prix = "$LOCATION->LOYER";
print "Réference : {$ref} <br />\n";
print "titre : {$prix} <br />\n";
print "id : {$id} <br />\n";
}
}
foreach ($BIEN->INTITULE as $INTITULE) {
$title = "$INTITULE->FR";
$title = addslashes($title);
$title = utf8_decode($title);
print "id : {$title} <br />\n";
}
foreach ($BIEN->COMMENTAIRES as $COMMENTAIRES) {
$commentaires = "$COMMENTAIRES->FR";
$commentaires = addslashes($commentaires);
$commentaires = utf8_decode($commentaires);
print "id : {$commentaires} <br />\n";
}
if ($BIEN->APPARTEMENT) {
foreach($BIEN->APPARTEMENT as $APPARTEMENT);
$type = "Appartement a";
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type_id = 1;
$floor = "$APPARTEMENT->NUM_ETAGE";
$bathrooms = "$APPARTEMENT->NBRE_SALLE_BAIN";
$living_space = "$APPARTEMENT->SURFACE_HABITABLE";
$room = "$APPARTEMENT->NBRE_PIECES";
$piece = "de $room pieces";
$dpe_energie = "$APPARTEMENT->CONSOMMATIONENERGETIQUE";
$dpe_ges = "$APPARTEMENT->VALEUR_GES";
}
if ($BIEN->MAISON) {
foreach($BIEN->MAISON as $MAISON);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Maison a";
$type_id = 2;
$bathrooms = "$APPARTEMENT->NBR_SALLE_BAIN";
$room = "$MAISON->NBRE_PIECES";
$piece = "de $room pieces";
$living_space = "$MAISON->SURFACE_HABITABLE";
$land_space = "$MAISON->SURFACE_TERRAIN";
$dpe_energie = "$MAISON->CONSOMMATIONENERGETIQUE";
$dpe_ges = "$MAISON->VALEUR_GES";
}
if ($BIEN->TERRAIN) {
foreach($BIEN->TERRAIN as $TERRAIN);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Terrain a";
$type_id = 3;
$living_space = 0;
$land_space = "$TERRAIN->SURFACE_TERRAIN";
}
if ($BIEN->DEMEURE) {
foreach($BIEN->DEMEURE as $DEMEURE);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = 'Demeure a';
$bathrooms = "$APPARTEMENT->NBR_SALLE_BAIN";
$room = "$DEMEURE->NBRE_PIECES";
$piece = "de $room pieces";
$living_space = "$DEMEURE->SURFACE_HABITABLE";
$land_space = "$DEMEURE->SURFACE_TERRAIN";
$type_id = 4;
$dpe_energie = "$DEMEURE->CONSOMMATIONENERGETIQUE";
$dpe_ges = "$DEMEURE->VALEUR_GES";
}
if ($BIEN->PARKING) {
foreach($BIEN->PARKING as $PARKING);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Parking a";
$type_id = 5;
}
if ($BIEN->FOND_COMMERCE) {
foreach($BIEN->FOND_COMMERCE as $FOND_COMMERCE);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Fond de commerce a";
$room = "$FOND_COMMERCE->NBRE_PIECES";
$type_id = 6;
}
if ($BIEN->LOCAL_PROFESSIONNEL) {
foreach($BIEN->LOCAL_PROFESSIONNEL as $LOCAL_PROFESSIONNEL);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Local-professionnel a";
$room = "$LOCAL_PROFESSIONNEL->NBRE_PIECES";
$piece = "de $room pieces";
$type_id = 7;
}
if ($BIEN->IMMEUBLE) {
foreach($BIEN->IMMEUBLE as $IMMEUBLE);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Immeuble a";
$type_id = 8;
$bathrooms = "$APPARTEMENT->NBR_SALLE_BAIN";
$room = "$IMMEUBLE->NBRE_PIECES";
$piece = "de $room pieces";
$living_space = "$IMMEUBLE->SURFACE_HABITABLE";
$land_space = "$IMMEUBLE->SURFACE_TERRAIN";
$dpe_energie = "$IMMEUBLE->CONSOMMATIONENERGETIQUE";
$dpe_ges = "$IMMEUBLE->VALEUR_GES";
}
if ($BIEN->FORET) {
foreach($BIEN->FORET as $FORET);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Foret a";
$type_id = 9;
}
if ($BIEN->AGRICOLE_VITICOLE) {
foreach($BIEN->AGRICOLE_VITICOLE as $AGRICOLE_VITICOLE);
$emphasis = "$APPARTEMENT->SELECTION_PAGE_ACCUEIL";
$type = "Agricole a";
$type_id = 10;
}
foreach($BIEN->LOCALISATION as $LOCALISATION) {
$ville = "$LOCALISATION->VILLE";
$ville = strtolower($ville);
$town = "$LOCALISATION->VILLE";
switch ($town) {
case "BARCELONNETTE":
$town_id = 1;
break;
case "ENCHASTRAYES":
$town_id = 2;
break;
case "UVERNET FOURS":
$town_id = 3;
break;
case "FAUCON DE BARCELONNETTE":
$town_id = 4;
break;
case "JAUSIERS":
$town_id = 5;
break;
case "LA CONDAMINE CHATELARD":
$town_id = 6;
break;
case "SAINT PAUL":
$town_id = 7;
break;
case "MEYRONNES":
$town_id = 8;
break;
case "LARCHE":
$town_id = 9;
break;
case "SAINT PONS":
$town_id = 10;
break;
case "LES THUILES":
$town_id = 11;
break;
case "LE LAUZET UBAYE":
$town_id = 12;
break;
case "LE SAUZE":
$town_id = 13;
break;
case "PRA LOUP":
$town_id = 14;
break;
case "MEOLANS REVEL":
$town_id = 15;
break;
}
$zip_code = "$LOCALISATION->CODE_POSTAL";
print "id : {$zip_code} <br />\n";
}
foreach ($BIEN->IMAGES as $IMAGES) {
$base_upload_dir = './images/com_jea/images/';
print "id : {$base_upload_dir} <br />\n";
if (is_dir("$base_upload_dir") == false)
{
mkdir ("$base_upload_dir", 0777);
}
$COMP=0;
foreach ($IMAGES->IMG as $IMG) {
$url = "$IMG";
$fichier = file_get_contents($url);
print "id : {$base_upload_dir} <br />\n";
echo "id : {$url} <br />\n";
echo "toto";
echo "$COMP <br /n";
if ("$COMP==0")
{
$upload_dir = "./images/com_jea/images/$id/";
if (is_dir("$upload_dir") == false)
{
mkdir ("$upload_dir", 0777);
}
$f = fopen("./images/com_jea/images/$id/main.jpg", 'w+');
fwrite($f, $fichier);
fclose($f);
$infos_img = getimagesize("./images/com_jea/images/$id/main.jpg");
$width_max = 400;
$height_max = 400;
$imgWidth = $infos_img[0];
$imgHeight = $infos_img[1];
$whFact = $width_max/$height_max;
$imgWhFact = $imgWidth/$imgHeight;
if($whFact < $imgWhFact){//Si largeur déterminante
$thumbWidth = $width_max;
$thumbHeight = round($thumbWidth/$imgWhFact);
} else { //Si hauteur déterminante
$thumbHeight = $height_max;
$thumbWidth = round($thumbHeight*$imgWhFact);
}
$imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
$imageresize = imagecreatefromjpeg("./images/com_jea/images/$id/main.jpg");
imagecopyresampled($imgThumb, $imageresize, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
imagejpeg($imgThumb, "./images/com_jea/images/$id/preview.jpg", 90);
$infos_img = getimagesize("./images/com_jea/images/$id/main.jpg");
$width_max = 120;
$height_max = 90;
$imgWidth = $infos_img[0];
$imgHeight = $infos_img[1];
$whFact = $width_max/$height_max;
$imgWhFact = $imgWidth/$imgHeight;
if($whFact < $imgWhFact){//Si largeur déterminante
$thumbWidth = $width_max;
$thumbHeight = round($thumbWidth/$imgWhFact);
} else { //Si hauteur déterminante
$thumbHeight = $height_max;
$thumbWidth = round($thumbHeight*$imgWhFact);
}
$imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
$imageresize = imagecreatefromjpeg("./images/com_jea/images/$id/main.jpg");
imagecopyresampled($imgThumb, $imageresize, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
imagejpeg($imgThumb, "./images/com_jea/images/$id/min.jpg", 90);
}
if ("$COMP!=0") {
echo "toto";
$upload_dir = "./images/com_jea/images/$id/secondary/";
if (is_dir("$upload_dir") == false)
{
mkdir ("$upload_dir", 0777);
}
$f = fopen("./images/com_jea/images/$id/secondary/$ref,$COMP.jpg",'w+');
fwrite($f, $fichier);
fclose($f);
$infos_img = getimagesize("./images/com_jea/images/$id/secondary/$ref,$COMP.jpg");
$upload_dir = "./images/com_jea/images/$id/secondary/preview";
if (is_dir("$upload_dir") == false)
{
mkdir ("$upload_dir", 0777);
}
$width_max = 400;
$height_max = 400;
$imgWidth = $infos_img[0];
$imgHeight = $infos_img[1];
$whFact = $width_max/$height_max;
$imgWhFact = $imgWidth/$imgHeight;
if($whFact < $imgWhFact){//Si largeur déterminante
$thumbWidth = $width_max;
$thumbHeight = round($thumbWidth/$imgWhFact);
} else { //Si hauteur déterminante
$thumbHeight = $height_max;
$thumbWidth = round($thumbHeight*$imgWhFact);
}
$imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
$imageresize = imagecreatefromjpeg("./images/com_jea/images/$id/secondary/$ref,$COMP.jpg");
imagecopyresampled($imgThumb, $imageresize, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
imagejpeg($imgThumb, "./images/com_jea/images/$id/secondary/preview/$ref,$COMP.jpg", 90);
$infos_img = getimagesize("./images/com_jea/images/$id/secondary/$ref,$COMP.jpg");
$upload_dir = "./images/com_jea/images/$id/secondary/min";
if (is_dir("$upload_dir") == false)
{
mkdir ("$upload_dir", 0777);
}
$width_max = 120;
$height_max = 90;
$imgWidth = $infos_img[0];
$imgHeight = $infos_img[1];
$whFact = $width_max/$height_max;gHeight);
imagejpeg($imgThumb, "./images/com_jea/images/$id/secondary/min/$ref,$COMP.jpg", 90);
}
$COMP=$COMP+1;
$imgWhFact = $imgWidth/$imgHeight;
if($whFact < $imgWhFact){//Si largeur déterminante
$thumbWidth = $width_max;
$thumbHeight = round($thumbWidth/$imgWhFact);
} else { //Si hauteur déterminante
$thumbHeight = $height_max;
$thumbWidth = round($thumbHeight*$imgWhFact);
}
$imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
$imageresize = imagecreatefromjpeg("./images/com_jea/images/$id/secondary/$ref,$COMP.jpg");
imagecopyresampled($imgThumb, $imageresize, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $im
if (file_exists("./images/com_jea/images/$id/secondary/$ref,0.jpg")) {
unlink ("./images/com_jea/images/$id/secondary/$ref,0.jpg");
}
}
}
$alias = "$type $ville $piece";
$sql = "REPLACE INTO xxx(id,ref,title,type_id,is_renting,town,town_id,zip_code,land_space,living_space,published,price,description,rooms,dpe_energie,dpe_ges,charges,floor,bathrooms,alias,emphasis) VALUES('$id','$ref','$title','$type_id','$is_renting','$town','$town_id','$zip_code','$land_space','$living_space','1','$prix','$commentaires','$room','$dpe_energie','$dpe_ges','$charges','$floor','$bathrooms','$alias','$emphasis')";
// on insère les informations du formulaire dans la table
mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
$id++;
}
mysql_close($db);
?>