What are the potential pitfalls of storing large files like PDFs in a MySQL database?

Storing large files like PDFs in a MySQL database can lead to increased database size, slower performance, and potential issues with backups and restores. It is recommended to store the files in a file system and only store the file path or reference in the database.

// Store file in file system
$targetDirectory = "uploads/";
$targetFile = $targetDirectory . basename($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile);

// Store file path in MySQL database
$sql = "INSERT INTO files (file_path) VALUES ('$targetFile')";
mysqli_query($conn, $sql);