function renameAndMove($fileName, $uid, $dir, $permissions)
{
    $returnValue = false;
    //echo 'rename("images/uploadedImages/'.$fileName.','.$newSRCFileName.');\n';
    if (file_exists('images/uploadedImages/' . $fileName)) {
        $path_parts = pathinfo('images/uploadedImages/' . $fileName);
        $newSRCFileName = 'images/' . $dir . '/src/' . $uid . '.' . $path_parts['extension'];
        rename('images/uploadedImages/' . $fileName, $newSRCFileName);
        chmod($newSRCFileName, $permissions);
        $newFileName = 'images/' . $dir . '/' . $uid . '.' . $path_parts['extension'];
        copy($newSRCFileName, $newFileName);
        chmod($newFileName, $permissions);
        deleteOldVendorImages($newFileName);
        $returnValue = $newFileName;
    }
    return $returnValue;
}
            if (!unlink($filePath)) {
                $unlinked = false;
            }
            if ($unlinked) {
                if ($image_type == IMAGETYPE_JPEG) {
                    //echo "jpeg";
                    imagejpeg($newImage, $filePath, 75);
                } elseif ($image_type == IMAGETYPE_GIF) {
                    //echo "gif";
                    imagegif($newImage, $filePath);
                } elseif ($image_type == IMAGETYPE_PNG) {
                    //echo "png";
                    imagepng($newImage, $filePath);
                }
                if ($permissions != null) {
                    chmod($filePath, $permissions);
                    chmod($storeOriginalFilePath, $permissions);
                }
            }
            imagedestroy($newImage);
        }
        //end if resize
    }
    //end if valid file type
}
include_once 'deleteOldVendorImages.php';
deleteOldVendorImages($filePath);
// Return Success JSON-RPC response
$uploadResult = ['uploaded' => true, 'filePath' => $filePath];
die(json_encode($uploadResult));
//die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');