<?php 
//Don't Forget to change this to your upload folder! 
$mypath=realpath("uploadphoto.php");
$mypath=str_replace("uploadphoto.php","",$mypath);
$mypath=str_replace("\\","/",$mypath);
$mypath=str_replace("admin","files",$mypath);
$upload_folder=$mypath."userfiles/";
echo "<small>";
//1st file uploaded
if ($_POST["btnSave"]!=''){
		if (!isset($_FILES['uploaded']['tmp_name'])) 
		{ 
			//send user back to the form 
			header("Location: uploadphoto.php"); 
			//exit(); 
		} 
		if (is_uploaded_file($_FILES['uploaded']['tmp_name'])) 
		{ 
			//Get the Filename and the File Type 
			$fileName = $_FILES['uploaded']['name']; 
			$fileType = $_FILES['uploaded']['type']; 
			$fileName=strtolower($fileName);
			 if (str_contains(str_replace(".jpg","",str_replace(".gif","",str_replace(".png","",$fileName))),".")) {
				 echo "Not a valid File";
				 die;
			 }

			if (str_contains($fileName,".jpg") || str_contains($fileName,".gif") || str_contains($fileName,".png")) 
			{ 
				

			//Check if the file exists 
			
			
			
					$fileName=str_replace(".","@",strtolower($fileName));
					$fileext=split("@",$fileName);
					$fileext=$fileext[1];
					
							$fileName="PHOTO-".genpasswordalpha(2)."-".genpasswordnum(16).".".$fileext;
					
					//echo $fileName;
					if (move_uploaded_file($_FILES['uploaded']['tmp_name'],$upload_folder.''.$fileName)) 
					{ 
						//File Uploaded! 
						
						
						echo "<br>File: ".$fileName." has been uploaded!"; 
						?>
						<script>
							window.opener.document.getElementById('photo2').src='userfiles/<?=$fileName;?>';
							window.opener.document.step3.image.value='<?=$fileName;?>';
							window.close();
						</script>
						<?						
						
					} 
					else 
					{ 
						echo "Unable to upload file: ".$fileName; 
						//include 'upload.php'; 
						exit(); 
					} 
			}
			else
			{
				echo "Only JPG,GIF and PNG file extension is allowed."; 
				//include 'upload.php'; 
				exit(); 
			} 
		} 
		else 
		{ 
			echo "No File Selected or File too Large!"; 
			//exit(); 
		} 
	echo "<BR>";
	
}

?>
