Jump to content

Recommended Posts

I'm making an account settings page for my website and I want to set up a preg to check if the url they give for their profile image ends with gif/jpg/jpeg/bmp/or png. I'm really new to preg_matching and already ran into a problem because I noticed pages sometimes have more than just 2-3 periods so I can't just make the preg check for the word after a period. I jumbled around what I know about preg_match and preg_match_all and tried to make a way to count the amount of periods in the url then get the last word after the last period but I am not sure if what I am attempting is possible. What I attempted which might make you pros cringe is this...

	if($_POST['getimg'] != '' || $_POST['getimg'] != ' ')
{
	$bambo = ' ';
	preg_match_all('/\./i', $_POST['getimg'], $jambo, PREG_PATTERN_ORDER);
	for($i = 0; $i <= $jambo[0]; $i++)
	{
		$baloo = '(\*)+\.';
                        //keep adding the preg info to $bambo for the amount of periods there are
		$bambo = $bambo.$baloo;
	}

	if(!preg_match('/^(http:\/\/\)+($bambo)?{2,4}$/i', $_POST['getimg'], $match))
	{
                        //error message
		$thepage = 'Format is:<br>http://www.page.com/img.type';
	}
	else
	{
                        if($match == 'gif' || $match == 'jpg' || $match == 'jpeg' || $match == 'bmp' || $match == 'png')
                        {
		       //add the url to the image section for the user in the database
                        }
                        else
                        {
                               $thepage = 'Allowed filetypes:<br>gif, jpg, jpeg, bmp, png';
                        }
	}
}

 

Is there anyway to salvage what I did to make it work or is there a link someone could relay me to that might be able to help? I've been stuck on this for a few days.

Link to comment
https://forums.phpfreaks.com/topic/90016-solved-preg_match/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.