Page 1 sur 1

upload d'image et redimention

Posté : 31 juil. 2010, 01:56
par mglcan
bonjour
voila je ne me suis jamais adressé a aucun forum mais la je bloque, sur un site que je fait pour un ami je cherche a uploader une image (la dessus pas de probleme) et a la redimensionner par la même occasion, et la je ne sais pas comment faire j'ai bien essayer quelque script trouver a droite a gauche pour les intégrer sur mon code mais je n'arrive a rien.
donc si quelqu'un ici peut m'aider et aurais une solution je lui serais bien reconnaissant

voila mon code :
<?php
function envoyerphoto($photo)
{
if(isset($_FILES[$photo]))
{
   unset($erreur);
  $extensions_ok = array('png', 'gif', 'jpg', 'jpeg', 'PNG', 'GIF', 'JPG', 'JPEG');
  $taille_max = 5242880;
  $dest_dossier = 'vagues/vagues/';
  if( $_FILES[$photo]['name'] != "")
  {
  if( !in_array( substr(strrchr($_FILES[$photo]['name'], '.'), 1), $extensions_ok ) )
  {
    $extensiontrouver = substr(strrchr($_FILES[$photo]['name'], '.'), 1);
    $erreur = 'erreur : '.$photo.'  : Veuillez sélectionner un fichier de type png, gif ou jpg ! et non: '.$extensiontrouver.' trouvée';
  }
  elseif( file_exists($_FILES[$photo]['tmp_name']) and filesize($_FILES[$photo]['tmp_name']) > $taille_max)
  {
  $tailletrouver = filesize($_FILES[$photo]['tmp_name']);
    $erreur = 'erreur:'.$photo.' : Votre fichier doit faire moins de 5 Mo ! et non : '.$tailletrouver;
  }
 if(!isset($erreur))
  {
    $dest_fichier = basename($_FILES[$photo]['name']);
    $dest_fichier = strtr($dest_fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
    $dest_fichier = preg_replace('/([^.a-z0-9]+)/i', '_', $dest_fichier);
    $controleexistence = $dest_dossier.$dest_fichier;
    if (file_exists($controleexistence)) {
    $erreur = 'erreur : '.$photo.'  : Fichier Déja existant, renomer et reessayez ';
	}
  }
  if(!isset($erreur))
  {
    $dest_fichier = basename($_FILES[$photo]['name']);
    $dest_fichier = strtr($dest_fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
   $dest_fichier = preg_replace('/([^.a-z0-9]+)/i', '_', $dest_fichier);
    move_uploaded_file($_FILES[$photo]['tmp_name'], $dest_dossier . $dest_fichier);
return ($dest_fichier);
  }
  else
  {
  $_SESSION['erreur'] = $erreur;
header("Location: deposezvosphotos.php");
  exit;
  }
 }
}
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $imagebien = envoyerphoto("fichier_vosphotos");
  $insertSQL = sprintf("INSERT INTO vosphotos (numero_vosphotos, nom_vosphotos, description_vosphotos, categorie_vosphotos, fichier_vosphotos) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['numero_vosphotos'], "int"),
                       GetSQLValueString($_POST['nom_vosphotos'], "text"),
                       GetSQLValueString($_POST['description_vosphotos'], "text"),
                       GetSQLValueString($_POST['categorie_vosphotos'], "int"),
                       GetSQLValueString($imagebien, "text"));

  mysql_select_db($database_ndcomposite, $ndcomposite);
  $Result1 = mysql_query($insertSQL, $ndcomposite) or die(mysql_error());

  $insertGoTo = "deposezvosphotos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_ndcomposite, $ndcomposite);
$query_deposezvosphoto = "SELECT * FROM vosphotos";
$deposezvosphoto = mysql_query($query_deposezvosphoto, $ndcomposite) or die(mysql_error());
$row_deposezvosphoto = mysql_fetch_assoc($deposezvosphoto);
$totalRows_deposezvosphoto = mysql_num_rows($deposezvosphoto);
?>

merci d'avance pour ceux qui me répondrons
miguel

Re: upload d'image et redimention

Posté : 03 août 2010, 11:12
par mglcan
non vraiment personne?