Annonce

#2 Re : Discussions » insertion d'url image dans base MSQL » 2014-09-30 11:33:42

je ne veut pas stocker l'image dans la base je veut juste stocker l'url pour ensuite lui faire apel sur un formulaire

#3 Discussions » insertion d'url image dans base MSQL » 2014-09-30 11:24:23

athena
Réponses : 3

Bonjour a tous je suis un peu nouveau en PHP
mais je travail en ce moment sur une base de donnee pour gestion des resources humaines
voila j'aimerais que lors de l'enregistrement d'un nouveau employe dans ma base que je puise oploader sa photo pour en en suite pourvoire afficher les information de l'employe et sa photo sur un aute formulaire php.
voila mon code:
<?php
include ('fonction.php');
if (isset($_POST['submit']))
{
   
    $matricule = htmlspecialchars(trim($_POST['matricule']));
    $nomprenom = htmlspecialchars(trim($_POST['nomprenom']));
    $datenaissance = htmlspecialchars(trim($_POST['datenaissance']));
    $photo=$_FILES['photo']['name'];
    $photo_tmp=$_FILES['photo']['tmp_nname'];
    $errors=array();
    if(!empty($photo_tmp))
    {
        $image=explode('.',$photo);
        $image_ext=end($image);
        if(in_array(strtolower($image_ext)array('png','jpg','jpeg'))===false)
        {
          $errors[]="veillez saisir une image";
               }
        }
        if(empty($errors))
        {
            fonction redimensionner
            function upload_photo($photo_tmp)
        }else echo $errors
   
    if ($matricule&&$nomprenom&&$datenaissance&&$photo)
    { echo "Information de l'employe  inserer avec success";
      
          mysql_connect('localhost','root','kisore1988');
          mysql_select_db('gestionemp');
          $query = mysql_query("
                 
                  INSERT INTO employe VALUES('$matricule','$nomprenom','$datenaissance','$photo')
                 
                 
                 
                  ");
       
       
    } else echo "Veillez saisir tout les champs";
}

?>
<title>Inscriptin Employe</title>
<body bgcolor="CCCCFF">
<h1>Enregistrer un employe</h1>
<form method="post" action="nouveauemp.php" enctype="multipart/form-data">
<p>Matricule</p>
<input type="text"  name="matricule">
<p>Nom et Prenom</p>
<input type="text" name="nomprenom">
<p>Date de Naissance</p>
<input type="date" name="datenaissance"><br></br>
<p>PHOTO</p>
<input type="file" name="photo"><br></br>
<input type="submit" name="submit" value="Valider">

</form>


</body>


Ma fonction.php

<?php
function upload_photo($photo_tmp)
{
    if(file_exists($photo_tmp))
    {
        $image_size=getimagesize($photo_tmp);
        if($image_size['mime']=='image/jpeg')
        {
            $image_src=imagecreatefromjpeg($photo_tmp);
        }elseif ($image_size['mime']=='image/png')
        {
            $image_src=imagecreatefrompng($photo_tmp);
        }else {echo "Votre image n'es pas valide";
              $image_src=false;
        }
        if ($image_src!==false)
        {
            $image_width=300;
            if ($image_size[0]<=$image_width)
            {
                $image_finale=$image_src;
            }else {
                $new_width[0]=$image_width;
                $new_height[1]=($image_size[1]/$image_size[0])*$image_width;
                $image_finale=imagecreatetruecolor($new_width[0],$new_height[1]);
                imagecopyresampled($image_finale,$image_src,0,0,0,0,$new_width[0],$new_height[1],
                        $image_size[0],$image_size[1]);
             }
            imagejpeg($image_finale,'photoemp/','','jpg');   
        }
    }
}



?>

Pied de page des forums

Propulsé par FluxBB