i am trying to validate my upload form and struggling with a couple of validation methods. i want to not allow the user to upload the file larger than 5mb i have changed my php.ini file to 5M and done some coding to make it work but when i upload a file larger than 5mb i want the screen to echo something like "file too large to upload" but i dont know how to put that in. could someone advise please (code is below)

my other question is how to check before my file is uploaded weather a file in the database has the same name. i am uploading images to a folder and storing the images path in the database please help it would be soo helpful!

PHP Code:
$filename =.  basename($_FILES['uploaded_file']['name']);
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['size']<= $max_size)
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
$target_path "images/";
$target_path $target_path basename$_FILES['uploaded_file']['name']); 

move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) {
"The file ".  basename$_FILES['uploaded_file']['name']). 
" has been uploaded";
$dbLink = new mysqli('localhost''root''''gallery');
mysqli_connect_errno()) {
"MySQL connection failed: "mysqli_connect_error());
// Gather all required data
$name $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$size intval($_FILES['uploaded_file']['size']);
$image_path $dbLink->real_escape_string($target_path);
$gallery_type $dbLink->real_escape_string($_POST['gallery_type']); 

//query to insert the data i had gathered into the database
$query "INSERT INTO `images` (`name`, `size`, `created`, `image_path`, `gallery_type_id`)
             VALUES ('
{$name}', {$size}, NOW(), '{$image_path}', '{$gallery_type}')";
//executes the query
      else {
'Error! A file was not sent!';
// Echo a link back to the main page
echo '<p>Click <a href="member-index.php">here</a> to go back</p>';