Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:42:07+00:00 2026-05-15T10:42:07+00:00

I found this snippet that says will only allow certain file types. Will it

  • 0

I found this snippet that says will only allow certain file types. Will it work and could someone bypass it to upload what ever file type they want? And could someone explain the substr part, i don’t get how it works..

<?php
function CheckExt($filename, $ext) {
    $name = strtolower($filename);
    if(substr($name, strlen($name) -3, 3) == $ext)
        return true;
    else
        return false;
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:42:08+00:00Added an answer on May 15, 2026 at 10:42 am

    A better way to check extensions

    function checkExt($filename, $ext)
    {
      $fnExt = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
      if(!is_array($ext)) {
        $ext = (array)$ext;
      }
      $ext = array_map('strtolower', $ext);
      return in_array($fnExt, $ext);
    }
    

    You can then call it like

    var_dump(checkExt('test.temp', 'tmp')); // false
    var_dump(checkExt('test.temp', array('tmp', 'temp'))); // true
    

    Avoid using substr as the extension length is unknown (you can use substr & strrpos as well but php provides this functionality for you)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this snippet to add to my .emacs that will, on save, strip
found this little code snippet that seems to do what i want, but im
I found this great code snippet that works wonderfully during circumstances that change a
In this snippet: find( sub { print found . $File::Find::name . \n; }, (.));
I've found this snippet: http://fssnip.net/8o But I'm working not only with retriable functions, but
could some one please explain this snippet of magento code found in loadByCustomerId() in
I found this snippet of code that generates a string of random characters. But
I found this snippet of code here that allows you to log into a
I am working with a CMS that needs pretty urls. I found this snippet
I have this cool little snippet that I found, which adds a shadow to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.