Invité
Invité n'ayant pas de compte PHPfrance
06 mars 2007, 22:13
Oui c'est exactement ce que j'ai fait, voici mon script:
function upload_and_miniature($chemin_original, $chemin_mini, $nom_fichier, $champ){
$repertoireDestination = "$this->destination";
$nomDestination = basename($_FILES[$champ]["name"]);
echo $nomDestination."<br>"; //test
if (eregi(".jpg", $nomDestination) == 'FALSE'|| eregi(".jpeg", $nomDestination) == 'FALSE') { //interdiction d'autres formats que jpg
$nomDestination .= ".txt";
}
if(!file_exists($repertoireDestination.$nomDestination) && (eregi(".jpg", $nomDestination) || eregi(".jpeg", $nomDestination))){
echo 'test 1: '.$repertoireDestination.$nomDestination.'<br>';//test
if (is_uploaded_file($_FILES[$champ]["tmp_name"])) {
echo 'temp_name: '.$_FILES[$champ]["tmp_name"].'<br>';//test
if (rename($nom_fichier,$repertoireDestination.$nomDestination)) { //on renomme
/*echo "Le fichier temporaire ".$_FILES["monfichier"]["tmp_name"].
" a été déplacé vers ".$repertoireDestination.$nomDestination;*/
//redimensionnement de l'original
$image_origine = imagecreatefromjpeg("$chemin_original/$nomDestination");
$largeur_origine = imagesx($image_origine);
$hauteur_origine = imagesy($image_origine);
$hauteur_mini = $hauteur_origine * 100 / $largeur_origine;
$image_finale = imagecreate(100, $hauteur_mini);
imagecopyresized($image_finale, $image_origine, 0, 0, 0, 0, 100, $hauteur_mini, imagesx($image_origine), imagesy($image_origine) );
imagejpeg($image_finale, "$chemin_mini/$nomDestination");
imagedestroy($image_finale);
//création de la vignette
/*$image_origine = imagecreatefromjpeg("$chemin_original/$nomDestination");
$largeur_origine = imagesx($image_origine);
$hauteur_origine = imagesy($image_origine);*/
$hauteur_mini = $hauteur_origine * 100 / $largeur_origine;
$image_finale = imagecreate(100, $hauteur_mini);
imagecopyresized($image_finale, $image_origine, 0, 0, 0, 0, 100, $hauteur_mini, imagesx($image_origine), imagesy($image_origine) );
imagejpeg($image_finale, "$chemin_mini/$nomDestination");
imagedestroy($image_finale);
return true;
} else {
echo "Le déplacement du fichier temporaire a échoué".
" vérifiez l'existence du répertoire ".$repertoireDestination;
}
} else {
echo "Le fichier n'a pas été uploadé (trop gros ?)";
}
}else{
echo "Un fichier porte déjà ce nom";
}
}
et je l'instacie avec ça:
function set_photo1(){
$this->chemin_original = "photos/";
$this->chemin_mini = "photos/mini/";
$this->destination = "C:\\wamp\\www\\immopap\\photos\\";
$this->id_table = "id_bien";
$this->record = "photo1";
$this->tbl = "tbl_biens";
$this->upload_and_miniature($this->chemin_original,$this->chemin_mini,$this->id_bien.'1.jpg','photo1');
}
là je sèche

Encore merci de ta participation
