<?php
$mtime = explode(' ', microtime());
$start_time = $mtime[0] + $mtime[1];

// Define a destination
$targetFolder = '/uploads/images'; // Relative to the root



if (!empty($_FILES) ) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	$fileParts = pathinfo($_FILES['Filedata']['name']); 
	$returnPath = 'images/'.md5($start_time).'.'.$fileParts['extension']; 
	$targetFile = rtrim($targetPath,'/') . '/' .md5($start_time).'.'.$fileParts['extension'];
	
	// Validate the file type
	
	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	
	if (in_array($fileParts['extension'],$fileTypes)) {
		move_uploaded_file($tempFile,$targetFile);
		echo $returnPath;
	} else {
		echo 'Invalid file type.';
	}
	
}

?>