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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?php
define ('SITE_ROOT', realpath(dirname(__DIR__)));
ini_set('display_errors',1);
include "../bdd.php";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0){
$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png");
$filename = $_FILES["photo"]["name"];
$filetype = $_FILES["photo"]["type"];
$filesize = $_FILES["photo"]["size"];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Erreur : Veuillez sélectionner un format de fichier valide.");
$maxsize = 5 * 1024 * 1024;
if($filesize > $maxsize) die("Error: La taille du fichier est supérieure à la limite autorisée.");
if(in_array($filetype, $allowed)){
if(file_exists("upload/" . $_FILES["photo"]["name"])){
echo $_FILES["photo"]["name"] . " existe déjà.";
} else{
$lien_p = date('YmdHis').".".$_FILES["photo"]["name"];
move_uploaded_file($_FILES["photo"]["tmp_name"], SITE_ROOT."/../uploads/Produits/".$lien_p);
echo "Votre fichier a été téléchargé avec succès.";
}
} else{
echo "Error: Il y a eu un problème de téléchargement de votre fichier. Veuillez réessayer.";
}
}
}
if (isset($_POST['type']))
$fam = $_POST['type'];
if (isset($_POST['nom']))
$nom = $_POST['nom'];
if (isset($_POST['desc']))
$desc = $_POST['desc'];
if (isset($_POST['ref']))
$ref = $_POST['ref'];
if (isset($_POST['fourni']))
$fourni = $_POST['fourni'];
if (isset($_POST['obs']))
$obs = $_POST['obs'];
if (isset($_POST['pa']))
$pa = $_POST['pa'];
if (isset($_POST['pv']))
$pv = $_POST['pv'];
if (isset($_POST['nbh']))
$nbh = $_POST['nbh'];
if (isset($_POST['statut']))
$statut = $_POST['statut'];
if (!isset($statut))
$statut = 0;
if (isset($_FILES["photo"]))
$req = $db->query("INSERT INTO articles (art_fam, art_nom, art_desc, art_ref, art_fournisseur, art_obs, art_pa, art_pv, art_nbh, art_actif, art_photo) VALUES (\"$fam\", \"$nom\", \"$desc\", \"$ref\", \"$fourni\", \"$obs\", \"$pa\", \"$pv\", \"$nbh\", \"$statut\", \"$lien_p\")");
else
$req = $db->query("INSERT INTO articles (art_fam, art_nom, art_desc, art_ref, art_fournisseur, art_obs, art_pa, art_pv, art_nbh, art_actif) VALUES (\"$fam\", \"$nom\", \"$desc\", \"$ref\", \"$fourni\", \"$obs\", \"$pa\", \"$pv\", \"$nbh\", \"$statut\")");
$req_last_id = $db->query("SELECT LAST_INSERT_ID() FROM articles");
$last_id = $req_last_id->fetch();
$new_id = $last_id[0];
$req->closeCursor();
$req_last_id->closeCursor();
header('Location: product-info.php?p_id='.$new_id.''); |
Partager