<?php
// Database connection details
$host = 'localhost';
$dbName = '';
$username = '';
$password = '';
$tableName = 'nft';
$uploadDirectory = 'uploads/';
require_once "authe.php";
// Assuming you have a user authentication system in place,
// retrieve the username of the logged-in user from the "users" table
$loggedInUserId = $_SESSION['username']; // Replace with the appropriate session variable for the logged-in user's ID
$loggedInUser = '';
try {
// Establish a connection to the database
$db = new PDO("mysql:host=$host;dbname=$dbName", $username, $password);
// Create the table if it doesn't exist
$db->exec("CREATE TABLE IF NOT EXISTS $tableName (id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(255), url VARCHAR(255), nftby VARCHAR(255), fileprice VARCHAR(255), filedescription VARCHAR(255), filesize VARCHAR(255), fileprop VARCHAR(255), filetype VARCHAR(255), fileroyal VARCHAR(255), filecoll VARCHAR(255), filebid VARCHAR(255))");
// Retrieve the logged-in user's username from the "users" table
$statement = $db->prepare("SELECT username FROM users WHERE username = ?");
$statement->execute([$loggedInUserId]);
$result = $statement->fetch(PDO::FETCH_ASSOC);
if ($result) {
$loggedInUser = $result['username'];
}
// Handle the file upload
$file = $_FILES['file'];
$filename = $_POST['filename'];
$fileprice = $_POST['fileprice']; // Replace with the actual name of the additional field
$filedescription = $_POST['filedescription']; // Replace with the actual name of the additional field
$filesize = $_POST['filesize']; // Replace with the actual name of the additional field
$fileprop = $_POST['fileprop']; // Replace with the actual name of the additional field
$filetype = $_POST['filetype']; // Replace with the actual name of the additional field
$fileroyal = $_POST['fileroyal']; // Replace with the actual name of the additional field
$filecoll = $_POST['filecoll']; // Replace with the actual name of the additional field
$filebid = $_POST['filebid']; // Replace with the actual name of the additional field
// Generate a unique file name
$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
$newFilename = uniqid() . '.' . $extension;
// Move the uploaded file to the uploads directory with the new file name
$destination = $uploadDirectory . $newFilename;
if (move_uploaded_file($file['tmp_name'], $destination)) {
// Store the filename, URL, username, and additional fields in the table
$statement = $db->prepare("INSERT INTO $tableName (filename, url, nftby, fileprice, filedescription, filesize, fileprop, filetype, fileroyal, filecoll, filebid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$url = 'https://example.com/translated/user/' . $destination; // Replace with your actual domain or URL
$statement->execute([$filename, $url, $loggedInUser, $fileprice, $filedescription, $filesize, $fileprop, $filetype, $fileroyal, $filecoll, $filebid]);
// Display a pop-up message and redirect to a different page
echo '<script>alert("File uploaded successfully."); window.location.href = "http://example.com/success-page.php";</script>';
exit;
} else {
echo 'Error uploading file.';
}
// Close the database connection
$db = null;
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
Instead of displaying the pop-up message and redirecting to the new page, it just echos it as text after uploading.