Example #1
0
 public function addProduit($libelle, $description, $prix, $marque, $categorie, $qte, $nomFichier, $nomTemporaire, $poidsFichier, $extension)
 {
     $date_rfcT = date(DATE_RFC822);
     $date_today = convert_rfc822_to_date($date_rfcT);
     $tab_today = explode("-", $date_today);
     $tab_today_deux = explode(" ", $tab_today[2]);
     $jour = $tab_today_deux[0];
     $date_today_e = '20' . $tab_today[0] . '-' . $tab_today[1] . '-' . $jour;
     $q = $this->db->prepare('INSERT INTO produit SET libelle_produit = :libelle, description = :description, prix = :prix, id_marque = :marque,
 id_categorie = :categorie, date_de_creation = :crea, date_last_maj = :maj');
     $q->bindValue(':libelle', $libelle);
     $q->bindValue(':description', $description);
     $q->bindValue(':prix', $prix);
     $q->bindValue(':marque', $marque);
     $q->bindValue(':categorie', $categorie);
     $q->bindValue(':crea', $date_today_e);
     $q->bindValue(':maj', $date_today_e);
     $succes_req1 = $q->execute();
     $id_produit = $this->db->lastInsertId();
     $nom_photo = $id_produit . '_' . $libelle;
     $nom_photo = supprime_espaceVide($nom_photo);
     if ($poidsFichier != 0) {
         // Si la taille du fichier est supérieure à la taille
         if ($poidsFichier < self::MAX_SIZE) {
             if (isExtAuthorized($extension)) {
                 $nomFichier = $nom_photo . strtolower(strrchr($nomFichier, "."));
                 $nomFichier = supprime_espaceVide($nomFichier);
                 $uploadOk = move_uploaded_file($nomTemporaire, self::DESTINATION_FOLDER . $nomFichier);
                 $q = $this->db->prepare('UPDATE produit SET nom_photo = :photo
         WHERE id_produit = :id');
                 $q->bindValue(':photo', $nomFichier);
                 $q->bindValue(':id', $id_produit);
                 $succes_req5 = $q->execute();
             }
         }
     }
     $q = $this->db->prepare('INSERT INTO stock SET Qte = :qte');
     $q->bindValue(':qte', $qte);
     $succes_req3 = $q->execute();
     $id_stock = $this->db->lastInsertId();
     $q = $this->db->prepare('INSERT INTO stock_relation_produit SET id_stock = :stock, id_produit = :produit');
     $q->bindValue(':stock', $id_stock);
     $q->bindValue(':produit', $id_produit);
     $succes_req4 = $q->execute();
     if ($succes_req1 == true && $succes_req3 == true && $succes_req4 == true && $succes_req5 == true) {
         return true;
     } else {
         return false;
     }
 }
Example #2
0
function record_file($key, $authExt = array("*.*"))
{
    global $avatar_maxsize, $avatar_maxh, $avatar_maxl;
    if (isset($_FILES[$key])) {
        for ($i = 0; $i < count($_FILES[$key]['name']); $i++) {
            // Nom temporaire sur le serveur:
            $nomUtilisateur = $_FILES[$key]["name"][$i];
            // Type du fichier choisi:
            $typeFichier = $_FILES[$key]["type"][$i];
            // Poids en octets du fichier choisit:
            $poidsFichier = $_FILES[$key]["size"][$i];
            // Code de l'erreur si jamais il y en a une:
            $codeErreur = $_FILES[$key]["error"][$i];
            // Contenu du fichier
            $dataFichier = $_FILES[$key]["tmp_name"][$i];
            if ($codeErreur > 0) {
                return $codeErreur;
            }
            $image_sizes = getimagesize($dataFichier);
            if ($poidsFichier <= 0) {
                // Si le poids du fichier est de 0 bytes, le fichier est invalide (ou le chemin incorrect) => message d'erreur
                return 13;
            }
            if ($avatar_maxsize > 0) {
                if ($poidsFichier >= $avatar_maxsize) {
                    // Si la taille du fichier est suprieure  la taille maximum spcifie => message d'erreur
                    return 12;
                }
            }
            if ($avatar_maxh > 0 && $avatar_maxl > 0) {
                if ($image_sizes[0] > $avatar_maxl or $image_sizes[1] > $avatar_maxh) {
                    return 9;
                }
            }
            if (!isExtAuthorized($typeFichier, $authExt)) {
                // On teste ensuite si le fichier a une extension autorise
                return 11;
            }
            if (!is_uploaded_file($dataFichier)) {
                return 10;
            }
            $ft = fopen($dataFichier, "r");
            $imgbinary = fread($ft, filesize($dataFichier));
            $data = base64_encode($imgbinary);
            insert_db('Caranille_Images', array('Image_Base64' => $data, 'Image_Name' => $nomUtilisateur, 'Image_Type' => $typeFichier));
            //, 'Image_ID'=>$DocID));
        }
        return 0;
    }
}