j.g. Posted August 17, 2007 Share Posted August 17, 2007 Hello List! I'm working on some file uploading code, and need to check the file type and then verify that it's either ".doc, .txt, .pdf, or .xls" -- if it's not one of those, display an error and not upload it. But, I'm not sure how to do this; I think I want to implement $_FILES[my_file_name]["type"] somehow, but I just don't know where to begin or how to implement it??? Would someone out there be able to help me get over this hump that I've been stuck on? Here's my file upload code: elseif (preg_match("/upload/i", $submit)) // $submit == "Save"; { if ($_FILES["glossary_file"]["tmp_name"] ) { if ( move_uploaded_file($_FILES["glossary_file"]["tmp_name"], $uploadpath.$_FILES["glossary_file"]["name"]) ) { $error_msg = "Successfully Uploaded Glossary File"; } else { $error_msg = "Error Uploading Glossary File"; } } else { $error_msg = "Error Uploading Glossary File"; } } Thanks in advance for your help and expertise! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/65489-how-to-checkverify-file-types/ Share on other sites More sharing options...
roopurt18 Posted August 17, 2007 Share Posted August 17, 2007 Never, ever, under any circumstances use the type field provided in the $_FILES array; it is set by the browser and not PHP or the web server. This means the value can be easily faked. Refer to this: http://www.php.net/manual/en/ref.fileinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/65489-how-to-checkverify-file-types/#findComment-326994 Share on other sites More sharing options...
j.g. Posted August 17, 2007 Author Share Posted August 17, 2007 OK - that's why I'm here...I'm not sure how to do it and thought that that would be how, but I guess I was wrong. Any suggestions? Thanks much! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/65489-how-to-checkverify-file-types/#findComment-327002 Share on other sites More sharing options...
roopurt18 Posted August 17, 2007 Share Posted August 17, 2007 Refer to this: http://www.php.net/manual/en/ref.fileinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/65489-how-to-checkverify-file-types/#findComment-327011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.