<?php

$host = "db1.leigh-co.com";
$username = "pastebin";
$password = "";
$db_name = "pastebin";

$conn = new mysqli($host, $username, $password, $db_name);

if (!file_exists('uploads')) {
    mkdir('uploads', 0777);
}

if (mysqli_connect_errno()) {
    echo "Database connection has failed";
    exit;
}
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

$newName = uniqid($more_entropy = true) . '.' . $ext;

move_uploaded_file($_FILES['file']['tmp_name'], 'obj/' . $newName);

echo "https://leigh-co.com/pb/obj/$newName";

$stmt = $conn->prepare("INSERT INTO files (filename) VALUES (?)");
if (!$stmt) {
    echo "Prepare failed: (" . $conn->errno . ") " . $conn->error . "<br>";
}
$stmt->bind_param('s', $newName);
$stmt->execute();
$stmt->close();

?>
