dadamssg Posted January 16, 2010 Share Posted January 16, 2010 i have a function that checks the extension to make sure its either a jpeg ,gif, or png. Its a bit messy and overkill i think. Can someone help me clean it up and more efficient? thanks ahead if(!preg_match('/[.](jpg)|(gif)|(png)|(jpeg)|(GIF)|(PNG)|(JPG)|(JPEG)$/', $_FILES['fupload']['name'])) { $_SESSION['mess'] = "Images must be JPG, GIF, or PNG."; extract($_POST); header("location: picupload.php?id={$_GET['id']}"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/188658-help-with-function/ Share on other sites More sharing options...
nrg_alpha Posted January 18, 2010 Share Posted January 18, 2010 Perhaps a pattern like this? /\.(?:gif|jpe?g|png)$/i The i modifier takes care of case insentivity, so gif or GIF / png or PNG will both work. as for jpg's I used jpe?g (since the e is optional, this will match jpg, JPG, jpeg, JPEG). Quote Link to comment https://forums.phpfreaks.com/topic/188658-help-with-function/#findComment-997400 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.