sh0wtym3 Posted September 30, 2008 Share Posted September 30, 2008 This code WAS working before, I edited the form that uses it a little, and now for some reason it won't work correctly. When I try to upload MP3s now it says: "1.mp3 cannot be uploaded. The only acceptable file format is .mp3" Which, of course, makes no sense. I tried to include every possible mp3 file type inside my array. Thanks in advance. // allow MIME file types $filetype = array('audio/mpeg','audio/mpeg3','audio/x-mpeg','audio/x-mpeg3','audio/x-mpeg-3','audio/mp3','audio/x-mp3','audio/x-mpeg-aac','audio/mpg','audio/mpg3','audio/mp4'); $ftype = false; // check if uploaded file type is allowed foreach($filetype as $type) { if ($type == $_FILES['frmfile']['type']) { $ftype = true; break; } } if ($ftype && $fsize && $_POST['frmname'] != '') { switch($_FILES['frmfile']['error']) { case 0: //rename the file $username = $_COOKIE['ID_my_site']; $new_file_name=UPL_FLD.$username.'_'.$file; //determine the filesize variable $filesize = $_FILES['frmfile']['size']; //Makes sure genre field was filled in if (!$_POST['genre']) { $msg = 'Please select a genre.'; break; } //Makes sure desc field was filled in if (!$_POST['desc']) { $msg = 'Please add a description.'; break; } // Insert a row of information into the table "music" putenv("TZ=US/Eastern"); $title = $_POST['frmname']; $desc = $_POST['desc']; $genre = $_POST['genre']; $timestamp = date('m/d/y g:ia'); mysql_query("INSERT INTO music (title, desc, genre, timestamp) VALUES('$title','$desc','$genre','$timestamp')") or die(mysql_error()); // move file to the upload folder $upload = move_uploaded_file($_FILES['frmfile']['tmp_name'],$new_file_name); if ($upload) { $msg = $_FILES['frmfile']['name'].' uploaded successfully'; } else { $msg = 'Error. Please try again.'; } break; case 3: $msg = 'Error. Please try again.'; break; default: $msg = 'Error - please contact administrator'; } } elseif ($_FILES['frmfile']['error'] == 4) { $msg = 'Please select file'; } elseif ($_POST['frmname'] == '') { $msg = 'Please add a title to your song'; } else { $msg = $_FILES['frmfile']['name'].' cannot be uploaded.'; if(!$ftype) { $msg .= ' The only acceptable file format is .mp3'; } if(!$fsize) { $msg .= 'Maximum file size is '.$maxfs; } } } Link to comment https://forums.phpfreaks.com/topic/126488-solved-restricting-upload-file-type-to-mp3-only/ Share on other sites More sharing options...
grahamb314 Posted September 30, 2008 Share Posted September 30, 2008 Can't you just take everything after the last '.' , put it into a variable and if that variable = 'mp3' then upload ? Link to comment https://forums.phpfreaks.com/topic/126488-solved-restricting-upload-file-type-to-mp3-only/#findComment-654060 Share on other sites More sharing options...
sh0wtym3 Posted September 30, 2008 Author Share Posted September 30, 2008 ... I don't know I grabbed this code from somebody's tutorial, but I just implemented your suggestion and added an if variable that checks the $filetype. Works now. Thanks man. Link to comment https://forums.phpfreaks.com/topic/126488-solved-restricting-upload-file-type-to-mp3-only/#findComment-654224 Share on other sites More sharing options...
grahamb314 Posted September 30, 2008 Share Posted September 30, 2008 I had some code too for you, but you've done it now Glad I can help! Link to comment https://forums.phpfreaks.com/topic/126488-solved-restricting-upload-file-type-to-mp3-only/#findComment-654249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.