What are the potential pitfalls of storing images in a MySQL database?

Storing images in a MySQL database can lead to performance issues and increased storage requirements. It is generally recommended to store images on the file system and only store the file path in the database for better performance.

// Example of storing image file on the file system and saving the file path in the database

// Save image file to a directory
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["image"]["name"]);
move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile);

// Save file path in the database
$imagePath = $targetFile;
$sql = "INSERT INTO images (image_path) VALUES ('$imagePath')";
$result = mysqli_query($conn, $sql);