<?php
session_start();
// Attaching file 

$ext = findexts ($_FILES['photoimg']['name']) ;
//echo $ext; die();
if($ext == 'pdf' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif' || $ext == 'doc' || $ext == 'docx' || $ext == 'xls' || $ext == 'xlsx'|| $ext == 'tiff' || $ext == 'gif')
{
	$ran = time();
	//echo $ran; die();
	$ran2 = $ran.".";
	$target = "../attachment/";
	$target = $target . $ran2.$ext;
	//echo $target; die();

 if(move_uploaded_file($_FILES['photoimg']['tmp_name'], $target))
												{
													
													$_SESSION['fileid'] = "";
													echo "<script>alert('The file has been uploaded sucessfully.');</script>";
													//echo "<strong>The file has been uploaded sucessfully.</strong>";
													$_SESSION['fileid'] = $ran2.$ext;
													//echo $_SESSION['photoid'];
													
												}
												else
												{
													echo"<script>alert('Sorry, there was a problem uploading your file.');</script>";
													//echo "Sorry, there was a problem uploading your file.";
												}	
}
else
{
     echo "Sorry, file format is not supported.";
}

function findexts ($filename){
		$filename = strtolower($filename) ;
		$exts = split("[/\\.]", $filename) ;
		//echo $filename.".".$exts;
		$n = count($exts)-1;
		//echo $n;die();
		$exts = $exts[$n];
		return $exts;
	}
   
?>