grahamb314 Posted September 26, 2008 Share Posted September 26, 2008 Hi all I have a bit of code that uploads a file (works fine) to a directory (if the dir isn't there, then it makes it :-) I need to only allow certain file types to be uploaded. (mp3, mp2, mp1, wav and ogg) does someone know how to implement that into my code? Thank you!! <?php $filename = "uploads/{$_SESSION['directory']}"; if (is_dir($filename)) { echo "The folder: $filename exists"; echo "<br>"; foreach($_FILES as $file_name => $file_array) { if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"], $filename.'/'.$file_array["name"]) or die ("Couldn't copy"); echo "The File: ".$file_array["name"]."<br/>\n"; echo "Was uploaded successfully to: "; echo $filename; /////////////////make a link to check? //////////////////////// }//file types allowed: mp3, mp2, mp1, wav and ogg } } else { mkdir("{$filename}", 0700); echo "The folder did not exist but has now been created"; echo "<br>"; foreach($_FILES as $file_name => $file_array) { if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"], $filename.'/'.$file_array["name"]) or die ("Couldn't copy"); echo "The File: ".$file_array["name"]."<br/>\n"; echo "Was uploaded successfully to: "; echo $filename; } } } ?> Link to comment https://forums.phpfreaks.com/topic/125976-limit-uploads-to-certain-file-extensions/ Share on other sites More sharing options...
grahamb314 Posted September 26, 2008 Author Share Posted September 26, 2008 Please let me know if you need more info! I`m really stuck on this one Link to comment https://forums.phpfreaks.com/topic/125976-limit-uploads-to-certain-file-extensions/#findComment-651467 Share on other sites More sharing options...
Alkimuz Posted September 26, 2008 Share Posted September 26, 2008 i have a code like that in my upload code for pictures, it goes as follows: // Does the file have the right MIME type? if ($_FILES[$filename]['type'] != 'image/pjpeg' AND $_FILES[$filename]['type'] != 'image/jpeg' AND $_FILES[$filename]['type'] != 'image/gif' AND $_FILES[$filename]['type'] != 'image/png' AND $_FILES[$filename]['type'] != 'image/wbmp') { echo 'the file you want to upload is no picture, please go back to try again'; exit; } i guess you can change that to mp3, mp2, mp1, wav and ogg Link to comment https://forums.phpfreaks.com/topic/125976-limit-uploads-to-certain-file-extensions/#findComment-651547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.