Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Why does this if statement not work?

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?
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

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/questions/26970736/Why-isn't-this-file-uploading.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!
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?