将图像上传到服务器并将其文件名存储在数据库可能具有挑战性。此外,将图像上传与从表单提交其他数据集成起来也存在困难。
更新后的表单包括以下更改:
PHP 代码连接到数据库并插入上传的图像和其他表单data.
数据库连接和数据插入:
// Connect to the database $connect = mysqli_connect("yourhost", "username", "password", "dbName"); // Write the information to the database $query = "INSERT INTO tableName (nameMember, bandMember, photo, aboutMember, otherBands) VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')"; mysqli_query($connect, $query);
图片上传:
// Image upload path $target = "your directory"; $target = $target . basename($_FILES['photo']['name']); if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { echo "The file has been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; }
以上是如何使用 PHP 将上传的图像文件名有效地存储在数据库中?的详细内容。更多信息请关注PHP中文网其他相关文章!