Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if (!$_SESSION["logged"]) {
  6.     header("Location: index.php");
  7.     exit;
  8. }
  9.  
  10. include_once "./php/config.php";
  11.  
  12. $empty = $size = $image = true;
  13.  
  14. if (!isset($_FILES['uploader'])) {
  15.     $empty = false;
  16.     exit;
  17. }
  18.  
  19. if ($_FILES['uploader']['size'] > 10485760) {
  20.     $size = false;
  21.     exit;
  22. }
  23.  
  24. $is_img = getimagesize($_FILES['userfile']['tmp_name']);
  25.  
  26. if (!$is_img) {
  27.     $image = false;
  28.     exit;
  29. }
  30.  
  31. $sql = "INSERT INTO gallery VALUES(':date',':name',':file')";
  32.  
  33. $stmt = $db->prepare($sql);
  34.  
  35. $date = date("Y-m-d");
  36. $name = addslashes($_FILES['uploader']['name']);
  37. $file = addslashes(file_get_contents($_FILES['uploader']['tmp_name']));
  38.  
  39. $stmt->bindValue(':date', $date);
  40. $stmt->bindValue(':name', $name);
  41. $stmt->bindValue(':file', $file);
  42.  
  43. $stmt->execute();
  44.  
  45. ?>
  46.  
  47. <!DOCTYPE html>
  48. <html lang="en">
  49.  
  50. <head>
  51.  
  52.     <meta charset="UTF-8">
  53.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  54.  
  55.     <link rel="stylesheet" href="css/Administration.css">
  56.  
  57.     <title>Irpiniart | Pannello di Controllo</title>
  58.  
  59.     <!-- JQuery -->
  60.  
  61.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  62.  
  63. </head>
  64.  
  65. <body>
  66.  
  67. <a id="log-out" href="login/logout.php">Esci</a>
  68.  
  69. <div id="container">
  70.  
  71.     <img src="resources/Upload.png" width="64px"/>
  72.  
  73.     <?php if (!$empty) {
  74.         ?>
  75.  
  76.         <div id="error-container">
  77.  
  78.             <p>Nessun file selezionato!</p>
  79.  
  80.         </div>
  81.  
  82.         <?php
  83.     }
  84.     ?>
  85.  
  86.     <?php if (!$size) {
  87.         ?>
  88.  
  89.         <div id="error-container">
  90.  
  91.             <p>Dimensioni file superiori a 10mb!</p>
  92.  
  93.         </div>
  94.  
  95.         <?php
  96.     }
  97.     ?>
  98.  
  99.     <?php if (!$image) {
  100.         ?>
  101.  
  102.         <div id="error-container">
  103.  
  104.             <p>Il file non è un'immagine!</p>
  105.  
  106.         </div>
  107.  
  108.         <?php
  109.     }
  110.     ?>
  111.  
  112.     <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
  113.  
  114.         <label for="file-upload" id="file">Seleziona immagine...</label>
  115.  
  116.         <br>
  117.  
  118.         <input id="file-upload" type="file" name="uploader" accept=".png, .jpg, .jpeg" required/>
  119.  
  120.         <br>
  121.         <br>
  122.  
  123.         <input class="btn-disabled" type="submit" value="Invia" disabled/>
  124.  
  125.     </form>
  126.  
  127. </div>
  128.  
  129. <script src="js/SelectImage.js"></script>
  130.  
  131. </body>
  132.  
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement