我想问一下如何通过PHP将数据添加到数据库,我正在使用MySQL。这是我的代码:
<?php
include 'conn.php';
$name = $_POST["name"];
$image = $_FILES["image"]["name"];
move_uploaded_file($_FILES["image"]["tmp_name"],"../upload/$image");
$query = "INSERT INTO practice VALUES('$name','$image')";
?>
我已经阅读了一些通过PHP添加图像的内容,但我仍然没有得到它:'(
答案 0 :(得分:0)
以下是Uploading image的链接。我希望它可以帮到你
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
这是上传图片的代码。您只需要获取文件的名称并将其存储在数据库中