Friday, September 2, 2011

Select Country Drop Down based on country location with flag with PHP

Selecting country name from country drop down based on the visitors country location will increase visitors user friendliness for your web forms, Let us create How to create Auto Select Country Name based on visitors location based on Country Geo location and  IP Address. When Loading a page detect country name and locate a country flag based on country location.




Create a Free Account for IP to Location API from http://ipinfodb.com/ip_location_api.php  to get a API Key for IP to Location. and get the Country Flag from ip2Location database.
using the URL: http://www.ip2location.com/images/country/{ COUNTRY SHORT CODE} .gif

and Process the code as per the following:

Thursday, September 1, 2011

Google profile style Image Uploader Script with PHP and jQuery

A Member request us, How to create a Google profile photo update style Image uploader using PHP and jQuery. Here is the solution for the Image Uploader like Google Profiles Change Photo Style


In this example I have use HTML Input file object replacer "prettyfile plugin".
here you can download the jQuery prettyFile Plugin and Use the following code to replace a file input like a "Update Photo" link. and Turn your interface look like a Google Profile Photo update page with PHP Ajax Uploader without refreshing the page.

Place the PHP Server Side Process on Page Top:

<?php session_start();

if(isset($_SESSION['updated_image']))
$existing_image=$_SESSION['updated_image'];
else
$existing_image='unknown.jpeg';


if(isset($_POST['image_process']))
{
	echo "<pre>";
	$filename=$_FILES['profile_photo']['name'];
	// Check whether the Uploaded file is Image file
	if(preg_match("/^[a-zA-Z0-9-_\.]+\.(jpg|gif|png|jpeg)$/",$filename))
	{
		// Check the Uploaded Image size is Less than or equal to 100 KB ( 1 KB == 1024 Bytes)
		if($_FILES['profile_photo']['size']<=102400)
		{
			$file_ext=end(explode(".",$filename));
			$filename="profile-".time().".$file_ext";
			if(move_uploaded_file($_FILES['profile_photo']['tmp_name'],"images/$filename"))			
			{
				$_SESSION['updated_image']=$filename;
			// Push Javascript Message on top Window		
			?>
			<script type="text/javascript">
			window.top.window.top.UploadStatus(0,'<?=$filename?>');
			</script>
			<?php					
			}else
			{
			// Push Javascript Message on top Window		
			?>
			<script type="text/javascript">
			window.top.window.top.UploadStatus(3);
			</script>
			<?php				
			}
			
		}else
		{
			// Push Javascript Message on top Window
		?>
        <script type="text/javascript">
		window.top.window.top.UploadStatus(2);
		</script>
        <?php			
		}
	}else
	{
			// Push Javascript Message on top Window		
		?>
        <script type="text/javascript">
		window.top.window.top.UploadStatus(1);
		</script>
        <?php
	}
	exit();
}


?>