pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP paste-bin - collaborative debugging tool View Help


Posted by Kud on Thu 3rd May 06:31
download | new post

  1. <?php
  2. //
  3. //      Formulaire d'envoi de fichier
  4. //
  5.  
  6. include('secure.php');
  7. include('config.php');
  8.  
  9. $date = date('Ymd');
  10. $time = date('H:i:s');
  11. // Taille maximum du fichier envoyé
  12. $taille_maxi = '100000000';
  13. // Extentions disponibles à l'envoi
  14. $extensions = array('.txt', '.pdf', '.dwg');
  15.  
  16. $modification_bouton = '';
  17.  
  18.  
  19. // Création du dossier stockant les fichiers en voyant s'il n'existe pas
  20. if (!is_dir($dossier))
  21.         {
  22.         mkdir($dossier,0777,TRUE);
  23.         }
  24.  
  25. if(isset($_GET['file']))
  26.         {
  27.         $modification_bouton = '<p>Changement :</p><p><input type="radio" checked="checked" name="modif" value="1" /><label>Important</label><input type="radio" name="modif" value="0" /><label>Minime</label></p>';
  28.         $modification = true;
  29.        
  30.         $sql = "SELECT * FROM fichier where fic_id = '" . $_GET['file'] . "'";
  31.         $result = pg_query($sql);
  32.         $version = pg_fetch_array($result);
  33.         $version = $version['fic_version'];
  34.         }
  35.        
  36. else   
  37.         {
  38.         $modification = false;
  39.         $version = '1.00';
  40.         }
  41.        
  42.  
  43. if(isset($_FILES['file']))
  44.         {
  45.         $fichier = basename($_FILES['file']['name']);
  46.         $taille = filesize($_FILES['file']['tmp_name']);
  47.         $extension = strrchr($_FILES['file']['name'], '.');
  48.         $commentaire = htmlentities ($_POST['commentaire'], ENT_QUOTES);
  49.         if($modification == true)
  50.                 {
  51.                 $modif = $_POST['modif'];
  52.                 if($modif == '0')
  53.                         {
  54.                         $version = $version + 0.01;
  55.                         }
  56.                 if($modif == '1')
  57.                         {
  58.                         $version = substr($version, 0, -3);
  59.                         $version = $version + 1 . '.00';
  60.                         }
  61.                 }       
  62.        
  63.         // Début des vérifications de sécurité
  64.         if(!in_array($extension, $extensions)) // Si l'extension n'est pas dans le tableau
  65.                 {
  66.             $erreur = '<p>Vous devez envoyer un fichier de type .txt, .pdf, .dwg...</p>';
  67.                 }
  68.                
  69.         if($taille>$taille_maxi)
  70.                 {
  71.             $erreur = '<p>Le fichier est trop gros.</p>';
  72.                 }
  73.                
  74.         if(!isset($erreur)) //S'il n'y a pas d'erreur -> envoi du fichier
  75.                 {
  76.             // On formate le nom du fichier
  77.             $fichier = strtr($fichier,
  78.                 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
  79.                 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
  80.                 $fichier = preg_replace('/([^.a-z0-9]+)/i', '', $fichier);
  81.                 $nb_extention = strlen($extension);
  82.                 $fichier = substr($fichier, 0, -$nb_extention);
  83.                 $nom_fichier = ucfirst($fichier);
  84.                 $fichier = $fichier . '_' . $date . '_' . $version . $extension;
  85.  
  86.                
  87.                 if(move_uploaded_file($_FILES['file']['tmp_name'], $dossier . $fichier)) // Si la fonction renvoie TRUE, c'est que ça a fonctionné
  88.                         {
  89.                 $message = '<p>Upload effectué avec succès !</p>';
  90.  
  91.                         if($modification == true)
  92.                                 {
  93.                                 $sql = "UPDATE fichier SET fic_nom = '$nom_fichier', fic_url = '$fichier', fic_date = '$date', fic_version = '$version' where fic_id = '" . $_GET['file'] . "'";
  94.                                 pg_query($sql);
  95.                                 }
  96.                                
  97.                         else
  98.                                 {
  99.                                 $sql = "INSERT INTO fichier VALUES (DEFAULT, '$nom_fichier', '$fichier', '$commentaire', '$date', '$time', '$version', '" .$_SESSION['id'] . "')";
  100.                                 pg_query($sql);
  101.                                 }
  102.  
  103.                         include('courriel.php');
  104.                         }
  105.                 else
  106.                         {
  107.                 $message = '<p>Echec de l\'upload !</p>';
  108.                         }
  109.                 $information = $message;
  110.                 }
  111.         else
  112.                 {
  113.                 $information = $erreur;
  114.                 }
  115.         }
  116.        
  117. else
  118.         {
  119.         $information = '';
  120.         }
  121.        
  122.  
  123. pg_close($dbconn);
  124. ?>
  125. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  126.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  127. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  128.         <head>
  129.                 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
  130.                 <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
  131.                 <title>Formulaire - Envoi de fichier</title>   
  132.         </head>
  133.         <body>
  134.                 <h1>Envoi de fichiers</h1>
  135.                 <div>
  136.                         <form method="post" action="formulaire.php<?php if(isset($_GET['file'])) { echo '?file=' . $_GET['file'];} ?>"  enctype="multipart/form-data">
  137.                             <p><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $taille_maxi ?>" /></p>
  138.                                 <p><label>Fichier (pdf, dwg, txt) : </label><input type="file" name="file" /></p>
  139.                                 <p><label for="commentaire">Commentaire : </label><textarea name="commentaire" id="commentaire" cols="30" rows="5"></textarea></p>
  140.                                 <?php echo $modification_bouton; ?>
  141.                                 <p><input type="submit" name="envoyer" value="Envoyer" /></p>
  142.                                 <?php echo $information; ?>
  143.                         </form>
  144.                 </div>   
  145.                 <p><a href="./liste.php">Voir la liste des fichiers</a></p>
  146.         </body>
  147. </html>

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@
:
:
Remember my settings