Created
September 2, 2012 20:31
-
-
Save anonymous/3604297 to your computer and use it in GitHub Desktop.
Php Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once "simple_html_dom.php"; | |
set_time_limit(0); | |
try | |
{ | |
$bdd = new PDO('mysql:host=localhost;dbname=facematch', 'root', ''); // Connection à la base de données | |
} | |
catch(Exception $e) | |
{ | |
die('Erreur : '.$e->getMessage()); | |
} | |
if (isset($_FILES['index']) AND $_FILES['index']['error'] == 0) | |
{ | |
$html= file_get_html($_FILES['index']['tmp_name']); // chargement de la page insérée dans le formulaire | |
$ret = $html->find('tr'); // On récupère toutes les personnes dans un tableau. Chaque case du tableau contient elle même un tableau qu'il faudra parser ensuite. | |
/* | |
if(!is_dir('photos/'.$_POST['promo'])){ | |
mkdir('photos/'.$_POST['promo'], 0777); // On crée le repertoire dans lequel on va stocker les photos des differentes promos | |
}*/ | |
$i=1; | |
$req = $bdd->prepare('INSERT INTO pool(pseudo, nom_complet, promo, email, photo, genre, votes, mot_de_passe, clef, actif) VALUES(:pseudo, :nom_complet, :promo, :email, :photo, :genre, :votes, :mot_de_passe, :clef, :actif)'); | |
for( $i=1 ; $i <(count($ret)-10) ; $i++){ | |
//$temp= str_get_html($ret[$i]); //Pour chaque personne on parse les éléments qui sont présents sur la page | |
$elements = str_get_html($ret[$i])->find('td'); //on stocke les differentes informations dans un tableau | |
//$link = str_get_html($ret[$i]); | |
$link = str_get_html($ret[$i])->find('a'); | |
$link_t= $link[1]->href; | |
//$photo=file_get_html($link[1]); // On parse la page détaillé de chaque personne | |
$photo = file_get_html($link_t)->find('img'); // on trouve la balise image | |
$photo_t= $photo[0]->src; | |
/* Script de téléchargement à revoir | |
$curl_handle=curl_init($photo[0]); | |
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0); | |
curl_setopt($curl_handle, CURLOPT_FILE, fopen("photos/".$_POST['promo']."/photo_".$i."jpg", 'wb')); | |
curl_setopt($curl_handle, CURLOPT_HTTPAUTH, "CURLAUTH_ANY"); | |
curl_setopt($curl_handle, CURLOPT_USERPWD, ":"); | |
curl_setopt($curl_handle, CURLOPT_HEADER, 0); | |
curl_exec($curl_handle); | |
curl_close($curl_handle); | |
*/ | |
// on récupère le texte : | |
//$elements[0] = str_get_html($elements[0]); | |
$nom_complet = str_get_html($elements[0])->plaintext; | |
//$elements[1] = str_get_html($elements[1]); | |
$mail = str_get_html($elements[1])->plaintext; | |
// On rajoute tout dans la base de donnée | |
$req->execute(array( | |
'pseudo' => '', | |
'nom_complet' => $nom_complet, | |
'promo' => $_POST['promo'], | |
'email' => $mail, | |
'photo' => $photo_t, | |
'genre' => '', | |
'votes' => 0, | |
'mot_de_passe' => '', | |
'clef' => '', | |
'actif' => 0 | |
)); | |
echo($i.'<br />'); | |
} | |
} | |
else { | |
echo('envoie de fichier a échouer'); | |
echo($_FILES['index']['error']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment