Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- if(empty($_FILES['uploaded_files'])){
- $files = '';
- } else {
- //Attach multiple files one by one
- for ($i = 0; $i < count($_FILES['uploaded_files']['tmp_name']); $i++) {
- if ($i == $maximumfiles) {
- throw new RuntimeException('<div class="alert">Sie haben zuviele Dateien hochgeladen.</div>');
- }
- if (!isset($_FILES['uploaded_files']['error'][$i])) {
- throw new RuntimeException('<div class="alert">Etwas mit Ihren Dateien stimmt nicht.</div>');
- }
- switch ($_FILES['uploaded_files']['error'][$i]) {
- case UPLOAD_ERR_OK:
- break;
- // case UPLOAD_ERR_NO_FILE:
- // throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint nicht verschickt worden zu sein.</div>');
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- throw new RuntimeException('<div class="alert">Eine Ihrer Dateien scheint von der Datenmenge groß zu sein.</div>');
- // default:
- // throw new RuntimeException('<div class="alert">Ein unbekannter Fehler ist aufgetreten.</div>');
- }
- if ($_FILES['uploaded_files']['size'][$i] > 5000000) {
- throw new RuntimeException('<div class="alert">Die maximale Dateigröße ist überschritten.</div>');
- }
- $extension = strtolower(pathinfo($_FILES['uploaded_files']['name'][$i], PATHINFO_EXTENSION));
- $allowed_extensions = array('jpg', 'jpeg', 'pdf');
- if(!in_array($extension, $allowed_extensions)) {
- throw new RuntimeException('<div class="alert">Nicht erlaubtes Dateiformat!</div>');
- }
- $allowed_types = array ('application/pdf', 'image/jpeg');
- $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
- $detected_type = finfo_file( $fileInfo, $_FILES['uploaded_files']['tmp_name'][$i] );
- if ( !in_array($detected_type, $allowed_types) ) {
- throw new RuntimeException('<div class="alert">Nicht erlaubtes Dateiformat!</div>');
- }
- finfo_close( $fileInfo );
- $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['uploaded_files']['name'][$i]));
- $filename = $_FILES['uploaded_files']['name'][$i];
- if (move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$i], $uploadfile)) {
- $files = $mail->addAttachment($uploadfile, $filename);
- } else {
- $msg .= 'Failed to move file to ' . $uploadfile;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment