Advertisement
Guest User

Form.php

a guest
Mar 17th, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. <?php
  2. use foundationphp\UploadFile;
  3.  
  4. session_start();
  5. require_once 'src/foundationphp/UploadFile.php';
  6. if (!isset($_SESSION['maxfiles'])) {
  7.   $_SESSION['maxfiles'] = ini_get('max_file_uploads');
  8.   $_SESSION['postmax'] = UploadFile::convertToBytes(ini_get('post_max_size'));
  9.   $_SESSION['displaymax'] = UploadFile::convertFromBytes($_SESSION['postmax']);
  10. }
  11. $max = 51200 * 1024;
  12. $result = array();
  13. if (isset($_POST['upload'])) {
  14.   $destination = __DIR__ . '/uploaded/';
  15.   try {
  16.     $upload = new UploadFile($destination);
  17.     $upload -> setMaxSize($max);
  18.     $upload -> allowAllTypes();
  19.     $upload -> upload();
  20.     $result = $upload -> getMessages();
  21.   } catch (Exception $e) {
  22.     $result[] = $e -> getMessage();
  23.   }
  24. }
  25. $error = error_get_last();
  26. ?>
  27. <!doctype html>
  28. <html lang="en">
  29.   <head>
  30.     <meta charset="UTF-8">
  31.     <title>Inleveren</title>
  32.     <link href="styles/form.css" rel="stylesheet" type="text/css">
  33.   </head>
  34.   <body>
  35.     <h1>Bestanden uploaden</h1>
  36.     <?php if ($result || $error) {
  37.     ?>
  38.     <ul class="result">
  39.       <?php
  40.       if ($error) {
  41.         echo "<li>{$error['message']}</li>";
  42.       }
  43.       if ($result) {
  44.         foreach ($result as $message) {
  45.           echo "<li>$message</li>";
  46.         }
  47.       }
  48.       ?>
  49.     </ul>
  50.     <?php } ?>
  51.     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
  52.       <p>
  53.  
  54.         <label for="username">Naam:</label>
  55.         <input type="text" name="name" id="" />
  56.         <br />
  57.  
  58.         <label for="class">Klas:</label>
  59.         <select name="class">
  60.           <option value="h4a">h4a</option>
  61.           <option value="h4b">h4b</option>
  62.           <option value="h4c">h4c</option>
  63.           <option value="h5a">h5a</option>
  64.           <option value="h5b">h5b</option>
  65.           <option value="h5c">h5c</option>
  66.         </select>
  67.         <br />
  68.  
  69.         <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
  70.         <label for="filename">Selecteer bestand:</label>
  71.         <input type="file" name="filename[]" id="filename" multiple
  72.         data-maxfiles="<?php echo $_SESSION['maxfiles']; ?>"
  73.         data-postmax="<?php echo $_SESSION['postmax']; ?>"
  74.         data-displaymax="<?php echo $_SESSION['displaymax']; ?>">
  75.       </p>
  76.       <ul>
  77.         <li>
  78.           Er kunnen <?php echo $_SESSION['maxfiles']; ?> bestanden tegelijkertijd worden geupload.
  79.         </li>
  80.         <li>
  81.           Elk bestand mag niet groter zijn dan <?php echo UploadFile::convertFromBytes($max); ?>.
  82.         </li>
  83.         <li>
  84.           Samen mag het niet meer dan <?php echo $_SESSION['displaymax']; ?> zijn.
  85.         </li>
  86.       </ul>
  87.       <p>
  88.         <input type="submit" name="upload" value="Inleveren">
  89.       </p>
  90.     </form>
  91.     <script src="js/checkmultiple.js"></script>
  92.     <?php
  93.     echo '<pre>';
  94.     print_r($_POST);
  95.     echo '</pre>';
  96.     ?>
  97.   </body>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement