[ Index ]

PHP Cross Reference of Project Glazy import

title

Body

[close]

/ -> upload.php (source)

   1  
   2  
   3  <?php
   4  include  'Global.php';
   5  
   6  
   7  function isJson($string) {
   8      return ((is_string($string) &&
   9              (is_object(json_decode($string)) ||
  10              is_array(json_decode($string))))) ? true : false;
  11  }
  12  
  13  function prompt($fname, $tmp){
  14    echo "<script type='text/javascript'> var answer = prompt('File name exist','".$fname."'); </script>";
  15  
  16    $answer = "<script type='text/javascript'> document.write(answer); </script>";
  17    return($answer);
  18  }
  19  
  20  include_once  'menu.php';
  21  
  22  echo '<div class="cadre" id="cadre" width="600" height="800">';
  23  
  24  /*
  25  $target_dir = "./fichiers/";
  26  $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  27  $uploadOk = 1;
  28  $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  29  // Check if image file is a actual image or fake image
  30  if(isset($_POST["submit"])) {
  31    $check = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
  32    if( isJson($check) !== false) {
  33      echo "File is Json ";
  34      $uploadOk = 1;
  35    } else {
  36      echo "File is not in json format";
  37      $uploadOk = 0;
  38    }
  39  }
  40  */
  41  
  42  // get all filename in directory
  43  $fileindir = array();
  44  $files = scandir('./fichiers/');
  45  foreach ($files as $fname) {
  46      if (!preg_match('/^\./',$fname)) {
  47        array_push($fileindir,$fname);
  48      }
  49  }
  50  
  51  $target_dir = "fichiers/";
  52  $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  53  $uploadOk = 1;
  54  
  55  // Check if image file is a proper json content file
  56  if(isset($_POST["submit"])) {
  57    $check = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
  58    if(isJson($check) !== false) {
  59      echo "Format de fichier correct (JSON).<br>";
  60      //  echo "<script> alert('json correct') </script>";
  61      $uploadOk = 1;
  62    } else {
  63      echo "Format de fichier incorrect (doit être JSON).<br>";
  64      $uploadOk = 0;
  65    }
  66  
  67  // Check file size
  68    if ($_FILES["fileToUpload"]["size"] > 500000) {
  69      echo "La taille est trop conséquente (plus de 500 kB): la taille est de".$_FILES["fileToUpload"]["size"]."<br>";
  70      $uploadOk = 0;
  71    }
  72  
  73  
  74  // Check if file already exists
  75  //if (file_exists($target_file)) {
  76    if (in_array($_FILES["fileToUpload"]["name"],$fileindir)) {
  77      // echo "Désolé, le nom de fichier est déjà utilisé.<br>";
  78      // echo "<script> alert('file exist " . $_FILES["fileToUpload"]["name"] . "') </script>";
  79      $valeur = prompt($_FILES["fileToUpload"]["name"],$_FILES["fileToUpload"]["tmp_name"]);
  80      if (in_array($_FILES["fileToUpload"]["name"], $fileindir)) {
  81        $uploadOk = 0;
  82      } else {
  83        $uploadOK = 1;
  84      }
  85    }
  86  
  87  
  88  
  89  // Check if $uploadOk is set to 0 by an error
  90    if ($uploadOk == 0) {
  91      echo "Désolé votre fichier n'a pas été téléversé.<br>";
  92    // if everything is ok, try to upload file
  93    } else {
  94      if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  95        echo "Le fichier ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " a été téléversé.";
  96        $fichier =  "fichiers/".$_FILES["fileToUpload"]["name"];
  97        if(!isset($_SESSION['fichier'])) {
  98          $_SESSION['filename'] = $fichier;
  99        }
 100        echo '<script>document.getElementById("fichier").value = "'.$fichier.'"; </script>';
 101      } else {
 102        echo "Désolé, il s'est produit une erreur lors du téléversage de votre fichier";
 103      }
 104    }
 105  }
 106  echo "</div>";
 107  ?>
 108  


Generated: Thu Sep 14 11:31:49 2023 Cross-referenced by PHPXref 0.7.1