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(); } 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). Link to comment https://forums.phpfreaks.com/topic/188658-help-with-function/#findComment-997400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.