Mustang  | J'ai un script d'upload de photo qui marche une foi sur deux.
   Il tourne sur une install toute propre de apache 2 et une foi sur deux quand on veux upper un fichier, le script dit que le fichier est parti mais en fait non
   la page : http://luckystallion.no-ip.org/test/
   le script :
  
  Code :
 - <html>
 - <head>
 - <title>Galerie</title>
 - </head>
 - <body>
 - Le mot de passe est "test" sans les guillemets
 - <?php
 - include("config.php" );
 - if(!isset($NomFichier))
 - {
 - 	afficher_formulaire_upload();
 - 	upload_liste_fichier();
 - }
 - else
 - {
 - 	if($mdp!=$motdepasse) die ("Mot de passe erroné" );
 - 	verif_fichier($NomFichier);
 - 	upload($NomFichier);
 - }
 - function alert($message)
 - {
 - echo "<br /><table align=\"center\" style=\"border:1px solid #C0c0c0;\"><tr><td><h4>$message</h4></td></tr></table>";
 - }
 - function verif_fichier($NomFichier)
 - {
 - 	if (!preg_match ("/^(.*)\.(jpg|png|gif|jpeg)$/i", $_FILES["NomFichier"]["name"] ))
 - 	{
 -     exit (alert("fichier non autorisé, on a le droit seulement aux extension jpg,jpeg,png,gif" ));
 - 	}
 - }
 - function tab_image()
 - {
 - //dossiers qui contient les fichiers
 - 	$d=opendir("." );
 - 	//scan du dossier
 - 	while($f=readdir($d))
 - 	{
 -   if (preg_match ("/^(.*)\.(jpg|png|gif|jpeg)$/i", $f))
 -   {
 -   	$is_image=true;
 -   }
 -   else
 -   {
 -   	$is_image=false;
 -   }
 -   if ($f != "." && $f != ".." && $f!="index.php" && $f!=".htaccess" && $is_image)
 -   $dir[]=$f;
 - 	}
 -   closedir();
 -   @sort($dir);
 - 	return $dir;
 - }
 - function tab_recherche($mot)
 - {
 - 	$dir=tab_image();
 - 	$num=count($dir);
 - 	$i=0;
 - 	while($i<$num)
 - 	{
 -   if (preg_match ("/^(.*)$mot(.*)$/i", $dir[$i]))
 -   {
 -   	$tab_recherche[]=$dir[$i];
 -   	//echo $dir[$i];
 -   }
 -   	$i++;
 - 	}
 - 	return $tab_recherche;
 - }
 - function upload_liste_fichier()
 - {
 - 	global $path,$HTTP_HOST,$REQUEST_URI,$nb_colone,$mot;
 - 	if(isset($mot) && $mot!="" )
 - 	{
 -   $dir=tab_recherche($mot);
 -   echo "<p align=\"center\"><a href=\".\" ><b>retour à la liste</b></a></p>";
 - 	}
 - 	else
 - 	{
 -   $dir=tab_image();
 - 	}
 -   //on compte le nombre de fichier trouvé dans le dossier
 -   $num=count($dir);
 - 	if($num==1 || $num==0)
 - 	{
 -   echo"<p>il y a $num fichier dans le dossier <b>http://".$HTTP_HOST."$REQUEST_URI</b></p>";
 - 	}
 - 	else
 - 	{
 -   echo"<p>il y a $num fichiers dans le dossier <b>http://".$HTTP_HOST."$REQUEST_URI</b></p>";
 - 	}
 -   $i=0;
 - 	echo "\n<table border=\"0\" width=\"90%\" align=\"center\"><tr bgcolor=\"#E4E4E4\">";
 - 	$width=100/$nb_colone;
 - 	$nb_ligne=0;
 - 	while($i<$num || $i%$nb_colone!=0)
 - 	{
 -   if($nb_ligne%2==0)
 -   {
 -   	$couleur="#F0F0F0";
 -   }
 -   else
 -   {
 -   	$couleur="#E4E4E4";
 -   }
 -   if($i<$num)
 -   {
 -   	if (preg_match ("/^(.*)\.gif$/i", $dir[$i]))
 -   	{
 -     echo "\n<td width=\"$width%\" ><a href=\"".$dir[$i]."\" target=\"_blank\">(pas de miniature) <br />".$dir[$i]."</a></td>";
 -   	}
 -   	else
 -   	{
 -     echo "\n<td width=\"$width%\" ><a href=\"".$dir[$i]."\" target=\"blank\"><img src=\"thumb.php?img=".$dir[$i]."\" border=\"0\"></a><br />".$dir[$i]."</td>";
 -   	}
 -   }
 -   else
 -   {
 -   	echo "\n<td width=\"$width%\"> ...</td>";
 -   }
 -   $i++;
 -   if($i%$nb_colone==0 &&$i!=0)
 -   {
 -   	if($i<$num)
 -   	echo "\n</tr>\n<tr bgcolor=\"$couleur\">";
 -   	else
 -   	echo "\n</tr>";
 -   	$nb_ligne++;
 -   }
 - 	}
 - 	echo"</table>";
 - }
 - function afficher_formulaire_upload()
 - {
 - 	echo'<div style="background:#C0C0C0;width:30%;">
 - 	<h4>Formulaire pour uploader une photo</h3>
 - 	<form ENCTYPE="multipart/form-data" method="post" name="upload">
 - 	<input name="mdp" type="password"> password<br />
 - 	<input name="NomFichier" type="file"><br />
 - 	<input type="SUBMIT" VALUE="Upload">
 - 	<input type="reset" name="Cancel " value="Cancel ">
 - 	</form> </div>';
 - 	echo'<table align="center"><tr><td><form >
 - 	<input name="mot" type="text"><input type="SUBMIT" VALUE="recherche">
 - 	</form></td></tr></table> ';
 - }
 - function upload($NomFichier)
 - {
 - 	global $HTTP_HOST,$REQUEST_URI;
 - 	if (file_exists($_FILES['NomFichier']['name']))
 - 	{
 -   echo"<h3>un fichier comporte deja ce nom</h3>";
 - 	}
 - 	else
 - 	{
 -   if(move_uploaded_file($_FILES["NomFichier"]["tmp_name"],$_FILES['NomFichier']['name'] ))
 -   {
 -   	echo '<h3>"'.$_FILES['NomFichier']['name'].'" a été envoyé sur le serveur avec succées</h3>';
 -   	echo '<input type="text" value="[img]http://'.$HTTP_HOST.$REQUEST_URI.$_FILES['NomFichier']['name'].'[/img]"><br /><br />';
 -   	echo '<img src="http://'.$HTTP_HOST.$REQUEST_URI.$_FILES['NomFichier']['name'].'">';
 -   }
 -   else
 -   {
 -   echo "<h3>upload echoué</h3><br />";
 -   }
 - 	}
 - }
 - ?>
 - </body>
 - </html>
 
  |  
    |