What are some alternative methods for storing images outside of the database?

Storing images directly in a database can lead to performance issues and increased database size. An alternative method is to store images outside of the database, such as on the server filesystem, and then store the file path in the database. This allows for quicker access to the images and reduces the load on the database.

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

// Save file path to database
$imagePath = $targetFile;
$query = "INSERT INTO images (image_path) VALUES ('$imagePath')";
mysqli_query($conn, $query);