View Full Version : upload mp3 file only

07-26-2005, 05:29 PM
I am trying to upload mp3 files only, but this code seems to allow any file type (I have tried both mp3 and jpg/gif)

Can someone show me what I am doing wrong?

if($_POST['submit']=="Upload") {
if ($_FILES['file']['name'] != "") {

if (eregi("\.mp3$", $_FILES['file']['type'])) {
echo "Please upload an mp3!<br /><br />";
echo "<a href=\"mp3upload.php\" title=\"Back to Uploads\">Go Back</a>";
if ($_FILES["file"]["size"] < 2000000) {

move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
echo "File has been stored in your uploads directory.";
}} else {
echo "Please upload a file that is under 2 mb!";

Thanks in advance.

07-26-2005, 06:11 PM
Try using

if($_FILES['file']['type'] == "audio/mpeg")

07-26-2005, 07:17 PM
Yeah Nightfire is on the right track, if that still doesn't work right, you could always have it print out of the value of the type property when you upload an MP3 so you can see what it shows up as.

Also, one minor thing I noticed was that you say upload a file under 2mb yet your code it set to block files bigger than 1.9mb, it probably wouldn't be a huge issue but if you want to make to more exact, it really should be:

if($_FILES["file"]["size"] < 2097152) {

Since there are 1024 bytes in one kilobyte and all.