Monkuar Posted July 2, 2009 Share Posted July 2, 2009 In my Photo Gallery, people submit photo's but it's a .gif or .jpg for the photo, how can I use php to help me on if a user doesnt have a .gif or a .jpg at the end of the url and then it gives them "Error Hey u need a .gif or .jpg at the end to submit" thanks. EDIT: They dont upload it's just a link to the image. Link to comment https://forums.phpfreaks.com/topic/164473-form-input-has-to-be-a-gif/ Share on other sites More sharing options...
arneman Posted July 2, 2009 Share Posted July 2, 2009 You can check if the last 4 digits are .GIF or .JPG Link to comment https://forums.phpfreaks.com/topic/164473-form-input-has-to-be-a-gif/#findComment-867604 Share on other sites More sharing options...
Monkuar Posted July 2, 2009 Author Share Posted July 2, 2009 You can check if the last 4 digits are .GIF or .JPG yea but how? lol Link to comment https://forums.phpfreaks.com/topic/164473-form-input-has-to-be-a-gif/#findComment-867605 Share on other sites More sharing options...
arneman Posted July 2, 2009 Share Posted July 2, 2009 Well, You get the length of the string: http://php.net/manual/en/function.strlen.php You take that number and subtract 4 from it. This way you will have your starting value for a substring function: http://be2.php.net/substr And then you compare that to the string ".jpg" or ".gif" or something like that. I would put every letter in a for loop and then use strtolower (http://php.net/manual/en/function.strtolower.php) or (http://php.net/manual/en/function.strtoupper.php) to compare. Since caps are not the same as small letters. But maybe there's a better way to do so. Link to comment https://forums.phpfreaks.com/topic/164473-form-input-has-to-be-a-gif/#findComment-867609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.