jfs

Fileupload exception

jfs
Oct 19th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. try {
  2.             if (array_key_exists('uploaded_files', $_FILES)) {
  3.                 //Attach multiple files one by one
  4.                 for ($i = 0; $i < count($_FILES['uploaded_files']['tmp_name']); $i++) {
  5.                     if ($i == $maximumfiles) {
  6.                         throw new RuntimeException('<div class="alert">Sie haben zuviele Dateien hochgeladen.</div>');
  7.                     }
  8.                     if (!isset($_FILES['uploaded_files']['error'][$i])) {
  9.                         throw new RuntimeException('<div class="alert">Etwas mit Ihren Dateien stimmt nicht.</div>');
  10.                     }
  11.                     switch ($_FILES['uploaded_files']['error'][$i]) {
  12.                         case UPLOAD_ERR_OK:
  13.                             break;
  14.                         // case UPLOAD_ERR_NO_FILE:
  15.                         //     throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint nicht verschickt worden zu sein.</div>');
  16.                         case UPLOAD_ERR_INI_SIZE:
  17.                         case UPLOAD_ERR_FORM_SIZE:
  18.                             throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint von der Datenmenge groß zu sein.</div>');
  19.                         // default:
  20.                         //     throw new RuntimeException('<div class="alert">Ein unbekannter Fehler ist aufgetreten.</div>');
  21.                     }
  22.                     if ($_FILES['uploaded_files']['size'][$i] > 5000000) {
  23.                         throw new RuntimeException('<div class="alert">Die maximale Dateigröße ist überschritten.</div>');
  24.                     }
  25.                     // if(in_array($finfo->file($_FILES['uploaded_files']['tmp_name'][$i]), $acceptedMime, true) === false){
  26.                     //   throw new RuntimeException('<div class="alert">Invalid file format.</div>');
  27.                     // }
  28.  
  29.  
  30.                     // if (false === $ext = array_search(
  31.                     //     $finfo->file($_FILES['uploaded_files']['tmp_name'][$i]),
  32.                     //     array(
  33.                     //         'jpg' => 'image/jpeg',
  34.                     //         'png' => 'image/png',
  35.                     //         'gif' => 'image/gif',
  36.                     //         'pdf' => 'application/pdf',
  37.                     //     ),
  38.                     //     true
  39.                     // )) {
  40.                     //     throw new RuntimeException('<div class="alert">Invalid file format.</div>');
  41.                     // }
  42.  
  43.                     $uploadfile = $_FILES['uploaded_files']['tmp_name'][$i];
  44.                     $filename = $_FILES['uploaded_files']['name'][$i];
  45.                 }
  46.             }
Advertisement
Add Comment
Please, Sign In to add comment