Are there any best practices or alternative methods for storing the original file path in a database when uploading files in PHP?

When uploading files in PHP, it is important to store the original file path in a database for reference. One common method is to store the file path in a separate column in the database table where the uploaded file details are stored. This allows for easy retrieval of the original file path when needed.

// Assuming $originalFilePath contains the original file path
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to insert file details including original file path
$sql = "INSERT INTO files (file_name, file_path, original_file_path) VALUES ('$fileName', '$filePath', '$originalFilePath')";

if ($conn->query($sql) === TRUE) {
    echo "File details inserted successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close database connection
$conn->close();