Sami Posted September 16, 2010 Share Posted September 16, 2010 How can I make my wetsite know what kind of file the user are uploading by filename instead of MIME?Because, when I should upload an mp3 file, the MIME type was "application/force-download"! Link to comment Share on other sites More sharing options...
trevelluk Posted September 16, 2010 Share Posted September 16, 2010 The original file name is in the file data array with the array index 'name'.So if for example your file upload field is called "myfile", you can get the original file name as $_FILES['myfile']['name'].Once you've got this then getting the extension is easy enough, either by using the pathinfo() function, or parsing the name yourself. Link to comment Share on other sites More sharing options...
Sami Posted September 17, 2010 Author Share Posted September 17, 2010 Just wanna know how to check the end of the filename(ex, if it is .mp3 or not) Link to comment Share on other sites More sharing options...
trevelluk Posted September 17, 2010 Share Posted September 17, 2010 Try this: $filename = $_FILES['myfile']['name'];$extension = pathinfo($filename, PATHINFO_EXTENSION);if($extension == 'mp3'){ print "This is an MP3 file";} More info at http://uk3.php.net/pathinfo Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.