?
Solved

Why does this if statement not work?

Posted on 2011-04-21
8
Medium Priority
?
279 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?
0
Comment
Question by:brucegust
7 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35441534
What does $filecheck and $ext look like? (echo it and post it here so we can work from there)
0
 
LVL 4

Assisted Solution

by:owner66
owner66 earned 500 total points
ID: 35441548
what does echo $ext; show?
0
 
LVL 13

Assisted Solution

by:F Igor
F Igor earned 500 total points
ID: 35441575
$_FILES['mp3_file']['tmp_name'] does not store the real filename.
Generally points to a temp filename like /tmp/php0456399303.tmp

If you want to check use
$filecheck =$_FILES['mp3_file']['name'];

This field stores the filename from browser

See:
http://php.net/manual/en/reserved.variables.files.php
for more information on $_FILES array.


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35442089
Why don't you use PHP pathinfo():
http://php.net/manual/en/function.pathinfo.php
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 500 total points
ID: 35442341
What does the
$_FILES["mp3_file"]["type"]
show ?
0
 

Author Comment

by:brucegust
ID: 35443136
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: http://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!
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35443194
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?
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question