Jump to content

help with function


dadamssg

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.