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 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
{
//IMAGE
$dossier = 'media/flag/';
$fichier = basename($_FILES['avatar']['name']);
$taille_maxi = 100000;
$taille = filesize($_FILES['avatar']['tmp_name']);
$extensions = array('.png', '.gif', '.jpg', '.jpeg');
$extension = strrchr($_FILES['avatar']['name'], '.');
//IMAGE
function continent($continent) { return empty($continent); }
function country($country) { return empty($country); }
function iso($iso) { return empty($iso); }
function exist($country, $continent) {
$sql='SELECT * FROM nation_country WHERE nation_country LIKE "'.addslashes($_POST['country']).'" AND nation_continent_ID LIKE "'.$_POST['continent'].'"';
$res=@mysql_query($sql);
return mysql_num_rows($res);
}
$form=1;
if (isset($_POST['envoyer'])||isset($_POST['envoyer_x'])||isset($_POST['envoyer_y'])) {
$continent=(!isset($_POST['continent']))?(''):($_POST['continent']);
$country=(!isset($_POST['country']))?(''):($_POST['country']);
$avatar=(!isset($_POST['avatar']))?(''):($_POST['avatar']);//IMAGE
$iso=(!isset($_POST['iso']))?(''):($_POST['iso']);
$msg='';
if( continent($continent) ) $msg.='<li>The field <strong>continent</strong> is empty !</li>';
if( country($country) ) $msg.='<li>The field <strong>country</strong> is empty !</li>';
if( iso($iso) ) $msg.='<li>The field <strong>iso</strong> is empty !</li>';
else {
if( exist($country, $continent) ) $msg.="<li>The combinaison <strong>continent/country</strong> already exist !</li>";}
//IMAGE
$fichier = strtr($fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
if (!empty($fichier)) {
if (!in_array($extension, $extensions)) $msg.="<li>Vous devez uploader un fichier de type png, gif, jpg, jpeg</li>";
if($taille>$taille_maxi) $msg.="<li>Le fichier est trop gros...!</li>";
};
if( empty($msg) ) {
if($form=='0') $msg.='Une erreur est survenue lors de l\'insertion d\'un client';
else {
$form=0;
//REDIMENSION
//REDIMENSION
move_uploaded_file($_FILES['avatar']['tmp_name'], $dossier . $fichier);
$requeteSQL='INSERT INTO nation_country (id_nation_country, nation_country, nation_country_iso, nation_continent_ID, logmaj, datemaj) VALUES ("", "'.addslashes($_POST['country']).'", "'.$_POST['iso'].'", "'.$_POST['continent'].'", "'.$_SESSION['GPR_loginID'].'", now() )';
$resultSQL=mysql_query($requeteSQL);
}
}
}
?> |
Partager