What are the potential pitfalls of manually storing image file paths in a database?

Potential pitfalls of manually storing image file paths in a database include the risk of inconsistent data entry, the possibility of broken links if the file paths change, and the potential for security vulnerabilities if the file paths are not properly sanitized. To mitigate these risks, it is recommended to store images in a separate directory on the server and only store the file name or a unique identifier in the database.

// Store image file in a separate directory on the server
$targetDir = 'uploads/';
$targetFile = $targetDir . basename($_FILES['image']['name']);

// Insert only the file name into the database
$imageFileName = basename($_FILES['image']['name']);
$query = "INSERT INTO images (file_name) VALUES ('$imageFileName')";