Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit file uploads to certain file extensions #25

Closed
gunemalli opened this issue Nov 13, 2017 · 1 comment
Closed

Limit file uploads to certain file extensions #25

gunemalli opened this issue Nov 13, 2017 · 1 comment

Comments

@gunemalli
Copy link

Hi There,

Love this script. Helped a lot with a few customers. I'd like to request a new feature if it's possible.

My requirement is that I only want a certain file extension to be able to be uploaded for security. Further to this, is it possible to lock down the file rename, not to be able to change the extension?

Regards
Asanka

@prasathmani
Copy link
Owner

prasathmani commented Nov 15, 2017

$total = count($_FILES['upload']['name']); $allowed = array('gif','png' ,'jpg');
for ($i = 0; $i < $total; $i++) {
	$filename = $_FILES['upload']['name'][$i];
    $tmp_name = $_FILES['upload']['tmp_name'][$i];
	$ext = pathinfo($filename, PATHINFO_EXTENSION);
    if (empty($_FILES['upload']['error'][$i]) && !empty($tmp_name) && $tmp_name != 'none' && in_array($ext,$allowed)) {
        if (move_uploaded_file($tmp_name, $path . '/' . $_FILES['upload']['name'][$i])) {
            $uploads++;
        } else {
            $errors++;
        }
    }
}
replace the code from line no 445. you can add allowed list of extension in $allowed.

ner00 pushed a commit to ner00/tinyfilemanager that referenced this issue May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants