Vous n'êtes pas identifié(e).
Pages : 1
Bonjour, voici la solution:
$errors=null;
/*les tests*/
if(isset($_FILES['uploadFile'])){
$filename = $_FILES['uploadFile']['name'];
$path = pathinfo($filename);
echo $filesext = $path['extension'];
$filesext = strtolower($filesext);
$extensions_autorisees = array('jpg','jpeg','pjpg','pjpeg','jpg','png','gif','tiff');
$destpath = './uploads_img/';
if ($_FILES['uploadFile']['error'] <= 0){
}else{
$errors.='Erreur lors de l\'upload image';
exit($errors);
}
if ($_FILES['uploadFile']['size'] <= 2097152){
}else{
$errors.='L\'image est trop lourde';
exit($errors);
}
if(in_array($filesext,$extensions_autorisees)){
}else{
$errors.='Le type MIME de l\'image n\'est pas bon';
exit($errors);
}
$img = @getimagesize($_FILES['uploadFile']['tmp_name']);
if($filesext==='jpg' && ($img['mime']==='image/jpg' || $img['mime']==='image/jpeg' || $img['mime']==='image/pjpeg')){
$jpgimg = imagecreatefromjpeg($_FILES['uploadFile']['tmp_name']);
$tjpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tjpgimg[1] * (($newlarg)/$tjpgimg[0])) );
$newjpgimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newjpgimg,$jpgimg,0,0,0,0,$newlarg,$newhaut,$tjpgimg[0],$tjpgimg[1]);
imagedestroy($jpgimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagejpeg($newjpgimg ,$destpath.$filerename,100);
}
elseif($filesext==='png' && ($img['mime']==='image/png' || $img['mime']==='image/x-png')){
$pngimg = imagecreatefrompng($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagepng($newpngimg, $destpath.$filerename,0);
}
elseif($filesext==='gif' && ($img['mime']==='image/gif')){
$gifimg = imagecreatefromgif($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagegif($newpngimg, $destpath.$filerename,0);
}
else{
}
}else{
}
?>
Bonjour,
Je suis entrain de créer un script pour upload et le redimensionnement d'images:
Avec les fichiers JPG tous ce passe bien, avec les fichiers PNG je n'ai aucun message d'erreur mais le fichiers n'est pas enregistré!
D'avance merci pour vos réponses...(je publie la totalité de mon script il y a un appel a du JS puis le formulaire et la partie PHP désolé pour la longueur...)
JS:
HTML:
<form id="uploadForm" enctype="multipart/form-data" action="test5.php" target="uploadFrame" onsubmit="uploadRun();" method="post" value="2097152">
<p> </p>
<p><input id="uploadFile" name="uploadFile" type="file" />
<input id="uploadSubmit" type="submit" value="télécharger" /></p>
<div align="left" class="vert" id="uploadStatus"></div>
<iframe id="uploadFrame" name="uploadFrame" src="#"></iframe>
</form>
PHP:
if(isset($_FILES['uploadFile']))
{
if ($_FILES['uploadFile']['error'] <= 0)
{
if ($_FILES['uploadFile']['size'] <= 2097152)
{
$filename = $_FILES['uploadFile']['name'];
$path = pathinfo($filename);
$filesext = $path['extension'];
$filesext = strtolower($filesext);
$extensions_autorisees = array('jpg', 'jpeg', 'pjpg', 'pjpeg', 'JPG', 'png', 'gif', 'tiff');
if (in_array($filesext, $extensions_autorisees))
{
$mimeext = array('jpg' => 'image/jpeg', 'jpeg'=>'image/jpeg', 'png'=>'image/png', 'gif'=>'image/gif', 'tiff'=>'image/tiff' );
$mimextie = array('jpg' => 'image/pjpeg', 'jpeg'=>'image/pjpeg');
if ($filesext == 'jpg' || $filesext == 'jpeg' || $filesext == 'pjpg' || $filesext == 'pjpeg')
{
$jpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
if($jpgimg['mime'] == $mimeext[$filesext] || $jpgimg['mime'] == $mimeextie[$filesext])
{
}
else
{
echo 'Le type MIME de l\'image n\'est pas bon';
}
$jpgimg = imagecreatefromjpeg($_FILES['uploadFile']['tmp_name']);
$tjpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tjpgimg[1] * (($newlarg)/$tjpgimg[0])) );
$newjpgimg = imagecreatetruecolor($newlarg , $newhaut) or die ("Erreur");
imagecopyresampled($newjpgimg , $jpgimg , 0,0, 0,0, $newlarg, $newhaut, $tjpgimg[0],$tjpgimg[1]);
imagedestroy($jpgimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagejpeg($newjpgimg , 'uploads_img/'.$filerename, 100);
if ($filesext == 'png')
{
$pngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
if($pngimg['mime'] == $mimeext[$filesext] || $pngimg['mime'] == $mimeextie[$filesext])
{
}
else
{
echo 'Le type MIME de l\'image n\'est pas bon';
}
$pngimg = imagecreatefrompng($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg , $newhaut) or die ("Erreur");
imagecopyresampled($newpngimg , $pngimg , 0,0, 0,0, $newlarg, $newhaut, $tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagepng($newpngimg, 'uploads_img/'.$filerename,0 );
}
else
{
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}
}
else
{
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}
}
else
{
echo 'L\'extension choisie pour l\'image est incorrecte';
}
}
else
{
echo 'L\'image est trop lourde';
}
}
else
{
echo 'Erreur lors de l\'upload image';
}
}
else
{
echo 'Prêt!';
}
$destpath = '/uploads_img/';
?>
JS:
Bonsoir,
Je suis débutant, j'ai un problème de connexion avec PDO, je ne comprend pas ou je me suis planté...
[code php]// Connexion à la base de données
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=dbuser7861', 'root', 'root', $pdo_options);
echo 'Je rentre le client<br>';
$req=$bdd->prepare('INSERT INTO comtes_clients(username, password, nom_animal, race_animal, date_naiss_client_J, date_naiss_client_m, date_naiss_client_a, titre, nom, prenom, societe, activite, adresse, adresse_s, ville, cp, email, tel) VALUES(:username, :password, :nom_animal, :race_animal, :date_naiss_client_J, :date_naiss_client_m, :date_naiss_client_a, :titre, :nom, :prenom, :societe, :activite, :adresse, :adresse, :ville, :cp, :email, :tel)');
$req->execute(array(
'username' => $username,
'passworde' => $password,
'nom_animal'=> $nom_animal,
'date_naiss_client_J' => $date_naiss_client_J,
'date_naiss_client_m' => $date_naiss_client_m,
'date_naiss_client_a' => $date_naiss_client_a,
'titre' => $titre,
'nom' => $nom,
'prenom' => $prenom,
'societe' => $societe,
'activite' => $activite,
'adresse' => $adresse,
'adresse_s' => $adresse_s,
'ville' => $ville,
'cp' => $cp,
'email' => $email,
'tel' => $tel
));
[/code]
Merci d'avance.
Pages : 1