delight-im / PHP-Foundation-Core

Core of “PHP-Foundation”
https://github.com/delight-im/PHP-Foundation
MIT License
6 stars 6 forks source link

Add 'hasUploads' and 'hasUpload' helpers #4

Closed ocram closed 7 years ago

ocram commented 7 years ago
function hasUploads() {
    return !empty($_FILES);
}

function hasUpload($name) {
    return isset($_FILES[$name]) && $_FILES[$name]['error'] != UPLOAD_ERR_NO_FILE;
}

We have to modify the second function so that it processes arrays like

my-input[]

from HTML inputs like

<input type="file" name="my-input[]">

correctly as well.

CC @rgvy

ocram commented 7 years ago

Implemented in https://github.com/delight-im/PHP-Foundation-Core/commit/d0a0fad1a48648e9da32df872bf4be7a757f5cc4

This handles simple names such as my-input and array-style names like my-input[] in two separate cases.