How does storing photos in a database affect the size and performance of the database?

Storing photos in a database can significantly increase the size of the database and potentially impact its performance. To address this issue, it is recommended to store the photos in a file system and only store the file path or reference in the database. This way, the database size remains manageable, and the performance is not compromised by storing large binary data.

// Example of storing a photo in a file system and saving the file path in a database
$photo = $_FILES['photo'];
$uploadDirectory = 'uploads/';
$uploadPath = $uploadDirectory . $photo['name'];

if (move_uploaded_file($photo['tmp_name'], $uploadPath)) {
    // Save the file path in the database
    $sql = "INSERT INTO photos (file_path) VALUES ('$uploadPath')";
    // Execute the SQL query
} else {
    echo "Failed to upload photo.";
}