使用最近上传的图像在PHP中更新数据库

I am trying to get the filename of an uploaded file so I can update a database, here is what I have at the moment. Using image Maniuplator

https://gist.github.com/philBrown/880506

<?php
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/ImageManipulator.php');

if ($_FILES['fileToUpload']['error'] > 0) {
    echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />";
} else {
    // array of valid extensions
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', '.PNG', '.GIF', '.bmp');
    // get extension of the uploaded file
    $fileExtension = strrchr($_FILES['fileToUpload']['name'], ".");
    // check if file Extension is on the list of allowed ones
    if (in_array($fileExtension, $validExtensions)) {
        $newNamePrefix = time() . '_';
        $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']);
        $width  = $manipulator->getWidth();
        $height = $manipulator->getHeight();
        $centreX = round($width / 2);
        $centreY = round($height / 2);
        // our dimensions will be 80by80
        $x1 = $centreX - 40; // 80
        $y1 = $centreY - 40; // 80

        $x2 = $centreX + 40; // 80
        $y2 = $centreY + 40; // 80

        // center cropping to 80by80
        $newImage = $manipulator->crop($x1, $y1, $x2, $y2);
        // saving file to uploads folder
        $manipulator->save('../images/avatars/uploaded/' . $newNamePrefix . $_FILES['fileToUpload']['name']);
        $user_image_1 = '$newNamePrefix';
        $user_image_2 = $_FILES['fileToUpload']['name'];
        $user_image_file = "{$domain}/images/avatars/uploaded/{$user_image_1}{$user_image_2}";
        // Update the DB with new avatar
            function set_new_avatar() {
                global $con, $user_id, $user_image_file;
                $sql = "UPDATE users SET user_image='$user_image_file' WHERE id='$user_id'";
                mysqli_query($con, $sql);
            }
        set_new_avatar();
        header('Location: ../index.php');

    } else {
        echo 'You must upload an image...';
    }
}
?> 

I have tried wrapping, $user_image_2 in (", also tried wrapping the variable in {} but nothing seems to work.

The file is uploaded and the database is being updated with [domain/images/avatars/uploaded/], but the problem is as it's being renamed during the upload and I can't capture the name.

I imagine it's a small syntax issue but I can't get my head around how to sort it out.

Thank you in advanced

There were 2 problems here, 1. User_image_1 was being passed as a variable and not a string.

$user_image_1 = '$newNamePrefix';

needed to be

$user_image_1 = $newNamePrefix;

The second was that user_id wasn't properly being passed to this screen and therefor it was blank.

I managed to find this out, by printing different aspects of the code rather than redirecting.