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

  FORUM HardWare.fr
  Programmation
  PHP

  Comment contrôler le nom du fichier uploadé

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment contrôler le nom du fichier uploadé

n°2104653
typicalcec​e
Posté le 04-10-2011 à 18:14:09  profilanswer
 

Bonjour,
j'ai créé un formulaire pour uploader un fichier vers un répertoire.
 
Je voudrais qu'en fonction du répertoire de destination que j'aurai taper dans le champ répertoire de destination, qu'il contrôle que le fichier uploadé corresponde au bon répertoire.
 
C'est pour éviter que je ne me trompe lorsque j'upload un fichier vers un répertoire.
 
Par exemple si le nom du répertoire est TOTO et que par le formulaire je tente d'uploadé un fichier qui ne comprend pas TOTO.., qu'il m’envoie sur une page d'erreur.
Je ne suis vraiment pas fort en php donc si vous pouvez me donner une réponse claire, elle sera la bienvenue!!
Merci par avance  
 
Ci-dessous mon code :

Code :
  1. <html>
  2. <head>
  3. <title></title>
  4. <meta http-equiv="Content-Type" content="text/html;">
  5. <!--Fireworks MX 2004 Dreamweaver MX 2004 target.  Created Fri Aug 12 15:35:16 GMT-0400 2005-->
  6. <script language="JavaScript" type="text/JavaScript">
  7. <!--
  8. function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  9.  if (init==true) with (navigator) {if ((appName=="Netscape" )&&(parseInt(appVersion)==4)) {
  10.    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  11.  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  12. }
  13. MM_reloadPage(true);
  14. //-->
  15. </script>
  16. <style type="text/css">
  17. <!--
  18. a.lien1
  19. {
  20. color:#000000;
  21. text-decoration:none;
  22. }
  23. a.lien1:hover
  24. {
  25. color:#000000;
  26. text-decoration:underline;
  27. }
  28. a.lien2
  29. {
  30. color:#9999FF;
  31. text-decoration:none;
  32. font-weight:bold;
  33. }
  34. a.lien2:hover
  35. {
  36. color:#FF9900;
  37. text-decoration:underline overline;
  38. font-weight:bold; }
  39. //-->
  40. </style>
  41. </head>
  42. <body bgcolor="#ffffff">
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. </div>
  52. <table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  53.  
  54.  <!--DWLayoutTable-->
  55.  <!-- fwtable fwsrc="" fwbase="index2.jpg" fwstyle="Dreamweaver" fwdocid = "1761606427" fwnested="0" -->
  56.  <tr>
  57.    <td><img src="../../images/spacer.gif" width="8" height="1" border="0" alt=""></td>
  58.    <td width="872"><img src="../../images/spacer.gif" width="872" height="1" border="0" alt=""></td>
  59.    <td><img src="../../images/spacer.gif" width="19" height="1" border="0" alt=""></td>
  60.    <td><img src="../../images/spacer.gif" width="1" height="1" border="0" alt=""></td>
  61.    <td><img src="../../images/spacer.gif" width="1" height="1" border="0" alt=""></td>
  62.  </tr>
  63.  <tr>
  64.    <td colspan="4"><img name="haut" src="../../images/haut.jpg" width="900" height="72" border="0" alt=""></td>
  65.    <td><img src="../../images/spacer.gif" width="1" height="72" border="0" alt=""></td>
  66.  </tr>
  67.  <tr>
  68.  
  69.  
  70.  
  71.  
  72.    <td ><img name="gauche" src="../../images/gauche.jpg" width="8" height="383" border="0" alt=""></td>
  73.    <td >
  74. <?php session_start();
  75.  
  76. include "config/config.php";             //config file inclusion
  77. include "includes/fonctions.inc.php";    //functions inclusion
  78. CloseUpload();                           //Application closing function
  79. include "includes/header.php";           //header inclusion
  80. include "lang/$lang.php";                //language inclusion
  81. echo "<center>";
  82.  
  83. // Detect if you have FTP extension loaded for PHP
  84. // Détecte si l'extension FTP de PHP est chargée.
  85. if(!DetectFtpExtension()) echo $ftpExtensionNotLoaded;
  86.  
  87. // inclusion de la classe de mail si necessaire
  88. // inclusion of the mail class if necessary
  89. if($prevenir_par_mail==1) include "includes/email_mime.class.php";
  90.  
  91. switch($a){
  92.  
  93.     //----------------------------------------
  94.     // Second Page
  95.     //----------------------------------------
  96.     case upload:
  97.         $error_id=0;
  98.         $error_ftp=0;
  99.  
  100.         //----------------------------------------
  101.         // authentification
  102.         //----------------------------------------
  103.         if($identification_nec==1) AuthentificationUser($login, $pass, $user);
  104.  
  105.         //----------------------------------------
  106.         // vérification du fichier
  107.         // file checking
  108.         //----------------------------------------
  109.         FileChecking($fichier_name, $fichier_size);
  110.  
  111.         //----------------------------------------
  112.         //Connection au serveur ftp
  113.         //Connection to the FTP server
  114.         //----------------------------------------
  115.         $connection_ftp=@ftp_connect("$ftp_server" );
  116.         $login_to_ftp=@ftp_login($connection_ftp, $ftp_user, $ftp_pass);
  117.         if((!$connection_ftp) || (!$login_to_ftp)) ++$error_ftp;
  118.  
  119.         if($error_ftp!=0){
  120.             echo $strErrorConnectionFtp."<br>";
  121.             logError("Can't connect to FTP server ($ftp_server) " );
  122.             makeReturn();
  123.             signMTA();
  124.             exit;
  125.         }
  126.  
  127.         //----------------------------------------
  128.         //changement de dossier
  129.         //directory change
  130.         //----------------------------------------
  131.         if(isset($destination))
  132.             $dossier_destination = $destination;
  133.         else
  134.             $dossier_destination = $ftp_rep_defaut;
  135.  
  136.         if(!@ftp_chdir($connection_ftp, $dossier_destination)){
  137.             echo $strErrorDestinationDirectory."le dossier de destination donn&eacute est :".$dossier_destination." et le test ".$test." et le nom".$nom_doc."<br><br>";
  138.             logError("Can't find destination directory (".$dossier_destination." ) " );
  139.             makeReturn();
  140.             signMTA();
  141.             exit;
  142.         }
  143.  
  144.         //---------------------------------------
  145.         // We verify that there is no file with
  146.         // the same name that the uploaded file.
  147.         // If yes, we rename the new file.
  148.         //----------------------------------------
  149.         $arrayFilesInDir = ftp_nlist($connection_ftp, "./" );
  150.         $renamed = false;
  151.  
  152.         if(in_array($fichier_name, $arrayFilesInDir)) {$newFileName=RenameFile($fichier_name);}
  153.         else    {$newFileName = $fichier_name;}
  154.  
  155.         //----------------------------------------
  156.         // File Upload
  157.         //----------------------------------------
  158.         $upload = ftp_put($connection_ftp, $newFileName, $fichier, FTP_BINARY);
  159.  
  160.         //----------------------------------------
  161.         // Upload verification
  162.         //----------------------------------------
  163.  
  164.         // Si Echec
  165.         // If Upload Failed
  166.  
  167.         if(!$upload){
  168.             logError("Upload failed !" );
  169.             echo "<center><h1>Upload</h1>";
  170.             echo $strErrorUploading." ".$newFileName."</center>";
  171.             makeReturn();
  172.             signMTA();
  173.  
  174.             $date_a=date("j/m/y à H:i", time());
  175.  
  176.             if($prevenir_par_mail==1){
  177.                 $mail = new mime_mail();
  178.                 $mail->to = "";
  179.                 $mail->subject = "Echech de la Mise à jour ";
  180.                 $mail->body = "Echec Mise à jour de votre extranet:\n".$nom_doc;
  181.                 $mail->body.= "Date: ".$date_a."<br>File: ".$newFileName."\n";
  182.                 $mail->body.= "IP: ".$REMOTE_ADDR;
  183.                 $mail->body.= "\n\n-----------------------------------------------------------\n";
  184.                 $mail->body.= "Cordialement,
  185.                                 ";
  186.                 $mail->from = "";
  187.                 $mail->send();
  188.             }
  189.         }
  190.  
  191.         // If upload OK
  192.         else{
  193.  
  194.             logUpload();
  195.  
  196.             echo "<center><h1>Upload</h1>".$strFile." ".$newFileName." (".$fichier_size." octets) ";
  197.             echo $strHasBeenUploaded."<br></center><br><br>";
  198.  
  199.             makeReturn();
  200.             signMTA();
  201.  
  202.             // Email
  203.             if($prevenir_par_mail==1){
  204.                 $mail = new mime_mail();
  205.     
  206.                 
  207.                 $mail->to = " , ".$Administrator['email'];
  208.                 $mail->subject = "Mise à jour de";
  209.                 $mail->body.= "Mise à jour de :\n".$nom_doc;
  210.     
  211.  
  212.                 $mail->body.= "\n\n-----------------------------------------------------------\n";
  213.                 $mail->body.= "Cordialement,
  214.                                 ";
  215.                 $mail->from = "";
  216.  
  217.  
  218.                 
  219.  
  220.  
  221.  
  222.  
  223.                 if($joindre_fichier==1){
  224.                     $fichier_attache = fread(fopen("$fichier", "r" ), filesize("$fichier" ));
  225.                     $mail->attach("$fichier_attache", "$newFileName" );
  226.                 }
  227.                 $flag=0;
  228.                 $mail->send();
  229.             }
  230.         }
  231.         
  232.         break;
  233.  
  234.         //----------------------------------------
  235.         // Default Page (first page)
  236.         //----------------------------------------
  237.     default:
  238.  
  239.         //log the visitor
  240.         logVisiteur();
  241.  
  242.         // Display the beginning of the form
  243.         DisplayBeginningForm();
  244.  
  245.         // if authentification is active, we display the login form
  246.         if($identification_nec == 1) DisplayLoginForm();
  247.  
  248.         // if directory choosing is active, we display the appropriate form
  249.         if($choisir_rep == 1) DisplayDirSelect();
  250.  
  251.         // display the end of the form
  252.         DisplayEndForm();
  253.         //signMTA();
  254.         break;
  255. }
  256. ?>
  257. </center></body></html>
  258.  
  259. </p>
  260.      <p align="center"></p>
  261.      <p align="justify"> </p>
  262.      <p align="justify"></p>
  263.      <p align="justify"> </p>
  264.      <p align="justify"> </p>
  265.      <p align="justify"></p>
  266.      <p align="justify"></p>
  267.      <p align="justify"><font size="2"><strong></strong></font></p>
  268.      <p align="justify"><font size="2"><strong></strong></font></p>
  269.    </td>
  270.    <td><img name="droite" src="../../images/droite.jpg" width="19" height="383" border="0" alt=""></td>
  271.    <td><img name="index2_r2_c4" src="../../images/index2_r2_c4.jpg" width="1" height="383" border="0" alt=""></td>
  272.    <td><img src="../../images/spacer.gif" width="1" height="383" border="0" alt=""></td>
  273.  </tr>
  274.  <tr>
  275.    <td colspan="4"><img name="bas" src="../../images/bas.jpg" width="900" height="75" border="0" alt=""></td>
  276.    <td><img src="../../images/spacer.gif" width="1" height="75" border="0" alt=""></td>
  277.  </tr>
  278. </table>
  279. </body>
  280. </html>


 
 
édité par Elmoricq : les titres tout en majuscules sont interdits + ajout des balises de présentation de code


Message édité par Elmoricq le 04-10-2011 à 18:52:04
mood
Publicité
Posté le 04-10-2011 à 18:14:09  profilanswer
 

n°2105240
typicalcec​e
Posté le 07-10-2011 à 14:56:24  profilanswer
 

Personne n'a une once de solution ?


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

  Comment contrôler le nom du fichier uploadé

 

Sujets relatifs
transformation du fichier XML vers TEX avec XSLTTester l'existence d'un fichier
Fichier Excel multipleInvisibilité
droit de fichier[DOS] Récupération valeur dans un fichier
Traitement de fichier avec AWKConversion d'un fichier XML en fichier WXR
Demande d'aide : Manipulation de fichier texte en .csv[VB] Modifier un fichier XML
Plus de sujets relatifs à : Comment contrôler le nom du fichier uploadé


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