jscix Posted April 19, 2007 Share Posted April 19, 2007 Okay, This is the first time I've attempted creating anything beyond a simple image upload. I would appreciate any helpful tips for ways to maximize validation for mp3 files. Beyond using, $_FILES["uploadedfile"]["type"] What ways can I make sure, the file is an valid mp3 file? Much appreciation in advance.. Link to comment https://forums.phpfreaks.com/topic/47806-mp3-upload-security-and-validation/ Share on other sites More sharing options...
per1os Posted April 19, 2007 Share Posted April 19, 2007 <?php $name = pathinfo($_FILES['uploadedfile']['name']); if (strtolower($name['extension']) != "mp3") { die("Not a valid type"); } ?> I am not sure if the tmpname is correct or not, but yea that is the idea. EDIT: Changed to name due to glyde's comment. Link to comment https://forums.phpfreaks.com/topic/47806-mp3-upload-security-and-validation/#findComment-233546 Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 It should be name, not tmpname. First of all tmpname isn't a valid attribute of the uploaded file, tmp_name is, but that's the path to the temp file, not the original file's filename. Link to comment https://forums.phpfreaks.com/topic/47806-mp3-upload-security-and-validation/#findComment-233548 Share on other sites More sharing options...
jscix Posted April 19, 2007 Author Share Posted April 19, 2007 yeah, i've created a function to validate the extention, Function ValidateFileXT($string) { $trimstr = substr($string, -4); $xt = strstr($trimstr, '.'); if (!$xt){ return False; } else { return $xt; } } eg: $file = strtolower(basename($_FILES['uploadedfile']['name'])); if (ValidateFileXT($file) == ".mp3") { //yay } but I was thinking more in terms of actual validation, I think I remember reading that the GD lib. Has a function: exif_imagetype() "exif_imagetype() reads the first bytes of an image and checks its signature." How difficult would this be to do with an mp3? Link to comment https://forums.phpfreaks.com/topic/47806-mp3-upload-security-and-validation/#findComment-233557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.