Page 1 sur 1

plusieurs images a uploader d'un coups ?

Posté : 12 août 2006, 18:34
par fabien14
Bonjour,

J'ai un bon petit script qui me convien parfaitement ... mais je ne sais pas comment faire en sorte que ya plusieurs image a uploader d'un coups ... je voudrai avoir la possiblilité 10 images d'un coups ....

Code : Tout sélectionner

<?php $path_thumbs = "images/mini"; $path_big = "images"; $img_thumb_width = 100; // in pixcel $extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no) //allowed Extensions $limitedext = array(".gif",".jpg",".png",".jpeg",".bmp"); //check if folders are Writable or not //please CHOMD them 777 if (!is_writeable($path_thumbs)){ die ("Erreur: Le dossier <b>($path_thumbs)</b> n'est pas accessible"); } if (!is_writeable($path_big)){ die ("Erreur: Le dossier <b>($path_big)</b> n'est pas accessible"); } //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Veuillez sélectionner une image!. <br />--<a href=\"$_SERVER[PHP_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "L'extension du fichier sélectionné n'est pas correcte. <br /><a href=\"$_SERVER[PHP_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } $resized_img = imagecreatetruecolor($newwidth,$newheight); imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image Imagepng ($resized_img,"$path_thumbs/$rand_name_mini.png"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name _mini.png\" target=\"_new\" >$path_thumbs/$rand_name_mini.png</a>"; } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$rand_name.$file_ext\" target=\"_new\">$path_big/$rand_name.$file_ext</a>"; echo "<br /><br/><a href=\"$_SERVER[PHP_SELF]\">Revenir a l'envoie de photo</a>"; }else{ //if the form hasn't been submitted. //print the form echo "<script> function view_img(img_name){ document[img_name].src = upForm.imgfile.value; document[img_name].width = 150; } </script> <br /><h3>Formulaire d'envoie de photos:</h3> <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"index.php?dest=envoie_dimage\"> <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\" /> <input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\" /> <br /><br /> <input type=\"Submit\" name=\"upForm\" value=\"Envoie de l'image\" /> <br /><br /> <img src='' name='img_vv' width='0'> </form>"; } ?>
Merci de votre aide :)

Posté : 12 août 2006, 18:42
par polo
Bonjour,
Une petit recherche sur google t'aurais aidé
Clique ici

Edit: de plus que je suis quasiment certain que le sujet a déjà été traité sur le forum, en faisant une petite recherche tu trouvera ton bonheur.

En espérant t'avoir aidé :D

Posté : 12 août 2006, 19:43
par fabien14
re coucou

J'ai trouver un autre script qui me parait bien mais j'ai une erreur ...
<?
if($_POST) {
	$msg = array(); // message
	$fichier = $_FILES['lefichier']; // simplication du tableau $_FILES
	for($i=0; $i<count($fichier['name']); $i++) {
		// nom du fichier original = nom par défaut
		$nom = $fichier['name'][$i];
		// test existence fichier
		if(!strlen($nom)) {
			$msg[] = "Aucun fichier !";
			continue;
		}
		// si un nouveau nom est renseigné (avec extension correcte)
		if(eregi($nametype, $_POST['lenom'][$i]))
			$nom = $_POST['lenom'][$i];
		// répertoire de destination
		$destination = $rep.$nom;
		// test erreur (PHP 4.3)
		if($fichier['error'][$i]) {
			switch($fichier['error'][$i]) {
				// dépassement de upload_max_filesize dans php.ini
				case UPLOAD_ERR_INI_SIZE:
				  $msg[] = "Fichier trop volumineux !"; break;
				// dépassement de MAX_FILE_SIZE dans le formulaire
				case UPLOAD_ERR_FORM_SIZE:
				  $msg[] = "Fichier trop volumineux (supérieur à ".(INT)($taillemax/1024)." Mo)"; break;
				// autres erreurs
				default:
				  $msg[] = "Impossible d'uploader le fichier !";
			}
		}
		// test taille fichier
		elseif($fichier['size'][$i] > $taillemax)
			$msg[] = "Fichier $nom trop volumineux : ".$fichier['size'][$i];
		// test type fichier
		elseif(!eregi($filetype, $fichier['type'][$i]))
			$msg[] = "Fichier $nom de type incorrect : ".$fichier['type'][$i];
		// test upload sur serveur (rep. temporaire)
		elseif(!@is_uploaded_file($fichier['tmp_name'][$i]))
			$msg[] = "Impossible d'uploader $nom";
		// test transfert du serveur au répertoire
		elseif(!@move_uploaded_file($fichier['tmp_name'][$i], $destination))
			$msg[] = "Problème de transfert avec $nom";
		else
			$msg[] = "Fichier <b>$nom</b> téléchargé avec succès !";
	}
	// affichage confirmation
	for($i=0; $i<=count($msg); $i++)
		echo "<p>$msg[$i]</p>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload</title>
<meta name="author" content="Pierre Pesty">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
/* variables à modifier */
$taillemax = 1512000000; // taille max d'un fichier (multiple de 1024)
$filetype = "(jpeg|gif|jpg|png)"; // types de fichiers acceptés, séparés par |
$nametype = "(.jpeg||.gif|.jpg|.jpeg)"; // extensions correspondantes
$rep = "upload/"; // répertoire de destination
$maxfichier = 10; // nombre maximal de fichiers
/* fin des modifications */
$recursif = "http://127.0.0.1/site/index.php?dest=2"; // simplification du fichier courant

### insérer le traitement ci-après ###

if(!$upload = $_GET['upload']) $upload = $_POST['upload'];
if(!$upload || $upload > $maxfichier) $upload = 1; // protection

// choix du nombre $upload de fichier(s)
echo "<form action='$recursif' method='post'>\n";
echo "Quantité <select name='upload' onChange=\"window.open(this.options[this.selectedIndex].value,'_self')\">\n";
for($i=1; $i<=$maxfichier; $i++) {
	echo "<option value='$recursif&upload=$i'";
	if($i == $upload) echo " selected";
	echo ">$i\n";
}
echo "</select>\n";
echo "<input name='upload' value='$upload' size='3'>\n";
echo "<input type='submit' value='Modifier'></form>\n";

// le formulaire
echo "<form action='$recursif' enctype='multipart/form-data' method='post'>\n";
// boucle selon nombre de fichiers $upload
for($i=1; $i<=$upload; $i++) {
	echo "<p>Nom $i <input name='lenom[]'>\n";
	echo "<input type='hidden' name='MAX_FILE_SIZE' value='$taillemax'>";
	echo "Fichier <input type='file' name='lefichier[]'></p>\n";
}
?>
<input type='submit' value='Envoyer'>
</form>

</body>
</html>
voici le message d'erreur ...

Code : Tout sélectionner

Warning: eregi(): REG_EMPTY in c:\documents and settings\stéph\bureau\site\lib\fenvoieimage.php on line 14 Fichier Sans-titre-2.jpg trop volumineux : 55547
le fichier que j'ai envoyé n'est pas du tous trops volumineux ... je comprend pas trops

Posté : 12 août 2006, 23:21
par iclo
Pourquoi changer de script ? Quelqu'un t'a donner des pistes de réponses maintenant c'est à toi de chercher un peu...
Lis la doc sur la fonction "eregi", ça te permettra de comprendre d'où peut venir l'erreur.


ps: utilise les balises PHP et non code.

Posté : 12 août 2006, 23:28
par Invité
J'ai chnager de script car celui ci correspond bien au attentes ... de plus on peu renomer les images avant envoi ....

Posté : 13 août 2006, 01:11
par Truc
Et bien maintenant que tu as un script essaie de le garder... tu n'auras certainement pas d'aide pour tous les nouveaux scripts.

Pour l'erreur as tu regardé la doc ( eregi() )comme il t'as été conseillé ?
Tu auras autant d'aide que nécessaire à condition que tu participes aux développement :wink: