We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Why does this if statement not work?

Bruce Gust
Bruce Gust asked
on
Medium Priority
313 Views
Last Modified: 2012-05-11
Here's my code:

$filecheck = basename($_FILES['mp3_file']['tmp_name']);
// this will return whatever is past the final . in the file name
$ext = strtolower(substr($filecheck, strrpos($filecheck, '.') + 1));
if (strtolower($ext) == 'mp3') {
echo "mp3";
}

The file in question is an mp3, but the code doesn't recognize that and I need to fix it. How?
Comment
Watch Question

Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
F IgorDeveloper
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Mohamed AbowardaSenior Software Engineer
CERTIFIED EXPERT

Commented:
Why don't you use PHP pathinfo():
http://php.net/manual/en/function.pathinfo.php
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Bruce GustPHP Developer

Author

Commented:
Hey guys!

I figured it out. The tmp_name thing is what was messing things up. Once I inserted that into the equation, I got what I needed. However, I'm still not where I need to be and if you're interested, head out to this question: https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26970736.html and you can help me figure out why although my path and file type are correct, the mp3 file isn't uploading.

Rock on!
Mohamed AbowardaSenior Software Engineer
CERTIFIED EXPERT

Commented:
I have posted a better way to get files extension, why did you accepted "NOT A SOLUTION" comment such as #35442341 and didn't accepted my solution while it's helpful for other people?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.