Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1672 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] Galerie d'image avec up | BUG

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[PHP] Galerie d'image avec up | BUG

n°738370
Mustang
Posté le 25-05-2004 à 19:04:49  profilanswer
 

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 :
  1. <html>
  2. <head>
  3. <title>Galerie</title>
  4. </head>
  5. <body>
  6. Le mot de passe est "test" sans les guillemets
  7. <?php
  8. include("config.php" );
  9. if(!isset($NomFichier))
  10. {
  11. afficher_formulaire_upload();
  12. upload_liste_fichier();
  13. }
  14. else
  15. {
  16. if($mdp!=$motdepasse) die ("Mot de passe erroné" );
  17. verif_fichier($NomFichier);
  18. upload($NomFichier);
  19. }
  20. function alert($message)
  21. {
  22. echo "<br /><table align=\"center\" style=\"border:1px solid #C0c0c0;\"><tr><td><h4>$message</h4></td></tr></table>";
  23. }
  24. function verif_fichier($NomFichier)
  25. {
  26. if (!preg_match ("/^(.*)\.(jpg|png|gif|jpeg)$/i", $_FILES["NomFichier"]["name"] ))
  27. {
  28.    exit (alert("fichier non autorisé, on a le droit seulement aux extension jpg,jpeg,png,gif" ));
  29. }
  30. }
  31. function tab_image()
  32. {
  33. //dossiers qui contient les fichiers
  34. $d=opendir("." );
  35. //scan du dossier
  36. while($f=readdir($d))
  37. {
  38.  if (preg_match ("/^(.*)\.(jpg|png|gif|jpeg)$/i", $f))
  39.  {
  40.   $is_image=true;
  41.  }
  42.  else
  43.  {
  44.   $is_image=false;
  45.  }
  46.  if ($f != "." && $f != ".." && $f!="index.php" && $f!=".htaccess" && $is_image)
  47.  $dir[]=$f;
  48. }
  49.  closedir();
  50.  @sort($dir);
  51. return $dir;
  52. }
  53. function tab_recherche($mot)
  54. {
  55. $dir=tab_image();
  56. $num=count($dir);
  57. $i=0;
  58. while($i<$num)
  59. {
  60.  if (preg_match ("/^(.*)$mot(.*)$/i", $dir[$i]))
  61.  {
  62.   $tab_recherche[]=$dir[$i];
  63.   //echo $dir[$i];
  64.  }
  65.   $i++;
  66. }
  67. return $tab_recherche;
  68. }
  69. function upload_liste_fichier()
  70. {
  71. global $path,$HTTP_HOST,$REQUEST_URI,$nb_colone,$mot;
  72. if(isset($mot) && $mot!="" )
  73. {
  74.  $dir=tab_recherche($mot);
  75.  echo "<p align=\"center\"><a href=\".\" ><b>retour à la liste</b></a></p>";
  76. }
  77. else
  78. {
  79.  $dir=tab_image();
  80. }
  81.  //on compte le nombre de fichier trouvé dans le dossier
  82.  $num=count($dir);
  83. if($num==1 || $num==0)
  84. {
  85.  echo"<p>il y a $num fichier dans le dossier <b>http://".$HTTP_HOST."$REQUEST_URI</b></p>";
  86. }
  87. else
  88. {
  89.  echo"<p>il y a $num fichiers dans le dossier <b>http://".$HTTP_HOST."$REQUEST_URI</b></p>";
  90. }
  91.  $i=0;
  92. echo "\n<table border=\"0\" width=\"90%\" align=\"center\"><tr bgcolor=\"#E4E4E4\">";
  93. $width=100/$nb_colone;
  94. $nb_ligne=0;
  95. while($i<$num || $i%$nb_colone!=0)
  96. {
  97.  if($nb_ligne%2==0)
  98.  {
  99.   $couleur="#F0F0F0";
  100.  }
  101.  else
  102.  {
  103.   $couleur="#E4E4E4";
  104.  }
  105.  if($i<$num)
  106.  {
  107.   if (preg_match ("/^(.*)\.gif$/i", $dir[$i]))
  108.   {
  109.    echo "\n<td width=\"$width%\" ><a href=\"".$dir[$i]."\" target=\"_blank\">(pas de miniature) <br />".$dir[$i]."</a></td>";
  110.   }
  111.   else
  112.   {
  113.    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>";
  114.   }
  115.  }
  116.  else
  117.  {
  118.   echo "\n<td width=\"$width%\">&nbsp;...</td>";
  119.  }
  120.  $i++;
  121.  if($i%$nb_colone==0 &&$i!=0)
  122.  {
  123.   if($i<$num)
  124.   echo "\n</tr>\n<tr bgcolor=\"$couleur\">";
  125.   else
  126.   echo "\n</tr>";
  127.   $nb_ligne++;
  128.  }
  129. }
  130. echo"</table>";
  131. }
  132. function afficher_formulaire_upload()
  133. {
  134. echo'<div style="background:#C0C0C0;width:30%;">
  135. <h4>Formulaire pour uploader une photo</h3>
  136. <form ENCTYPE="multipart/form-data" method="post" name="upload">
  137. <input name="mdp" type="password"> password<br />
  138. <input name="NomFichier" type="file"><br />
  139. <input type="SUBMIT" VALUE="Upload">
  140. <input type="reset" name="Cancel " value="Cancel ">
  141. </form> </div>';
  142. echo'<table align="center"><tr><td><form >
  143. <input name="mot" type="text"><input type="SUBMIT" VALUE="recherche">
  144. </form></td></tr></table> ';
  145. }
  146. function upload($NomFichier)
  147. {
  148. global $HTTP_HOST,$REQUEST_URI;
  149. if (file_exists($_FILES['NomFichier']['name']))
  150. {
  151.  echo"<h3>un fichier comporte deja ce nom</h3>";
  152. }
  153. else
  154. {
  155.  if(move_uploaded_file($_FILES["NomFichier"]["tmp_name"],$_FILES['NomFichier']['name'] ))
  156.  {
  157.   echo '<h3>"'.$_FILES['NomFichier']['name'].'" a été envoyé sur le serveur avec succées</h3>';
  158.   echo '<input type="text" value="[img]http://'.$HTTP_HOST.$REQUEST_URI.$_FILES['NomFichier']['name'].'[/img]"><br /><br />';
  159.   echo '<img src="http://'.$HTTP_HOST.$REQUEST_URI.$_FILES['NomFichier']['name'].'">';
  160.  }
  161.  else
  162.  {
  163.  echo "<h3>upload echoué</h3><br />";
  164.  }
  165. }
  166. }
  167. ?>
  168. </body>
  169. </html>

mood
Publicité
Posté le 25-05-2004 à 19:04:49  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] Galerie d'image avec up | BUG

 

Sujets relatifs
[PHP] Une petite précision sur date()Problême espace membres en PHP
[PHP - resolu] Input type file et Easyphp1.7[Débutant] Socket en C + interaction avec du PHP
[Php/Mysql/Tableaux] Optimisation d'un codeDoc PHP problème [Résolu]
Affichage et rafraichissement d'imageMoteur de recherche en PHP surun DOC XML
[PHP] Forward declaration ?pb pour insérer image dans page HTML avec un script cgi .pl
Plus de sujets relatifs à : [PHP] Galerie d'image avec up | BUG


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR