Php 无法将图像上载到数据库
所以我写了这个脚本,我一直无法上传消息,请指出我哪里做错了,请给脚本一个很好的例子。图像未上载到数据库,但已移动到“upload/”目录。$start&$stop变量的日期为。我已经在这里面呆了好几天了。这是密码Php 无法将图像上载到数据库,php,mysql,image,upload,Php,Mysql,Image,Upload,所以我写了这个脚本,我一直无法上传消息,请指出我哪里做错了,请给脚本一个很好的例子。图像未上载到数据库,但已移动到“upload/”目录。$start&$stop变量的日期为。我已经在这里面呆了好几天了。这是密码 include "../config/database.php"; $title = $_POST['title']; $id = $_POST['id']; $genre = $_POST['genre']; $start = $_POST['start']; $stop = $_
include "../config/database.php";
$title = $_POST['title'];
$id = $_POST['id'];
$genre = $_POST['genre'];
$start = $_POST['start'];
$stop = $_POST['stop'];
$description = $_POST['description'];
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOK = 1;
$imagetype = pathinfo($target_file, PATHINFO_EXTENSION);
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if ($check !== false) {
echo "File is an image -" . $check["mime"] . ".";
$uploadOK = 1;
} else{
echo "File isn't an image.";
$uploadOK = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file is already exist.";
$uploadOK = 0;
}
if ($_FILES["image"]["size"] > 5000000) {
echo "Sorry, file is too large.";
$uploadOK = 0;
}
if ($imagetype != "jpg" && $imagetype != "jpeg" && $imagetype != "png" && $imagetype != "gif") {
echo "Sorry, only JPEG, JPG, PNG and GIF are allowed.";
$uploadOK = 0;
}
if ($uploadOK == 0) {
echo "Failed to upload.";
} else {
if(move_uploaded_file($_FILES["image"]["tmp_name"] , $target_file)){
$query = mysql_query("INSERT INTO anidata (id, title, image, genre, start, stop, description) VALUES ('$title', '$id', '$target_file', '$genre', '$start', '$stop', '$description') ");
$uploadOK = 1;
if ($query) {
header("Location: view.php");
}else{
echo "<p>Failed to upload</p>";
}
}
}
包括“./config/database.php”;
$title=$_POST['title'];
$id=$_POST['id'];
$GREEP=$_POST['GREEP'];
$start=$_POST['start'];
$stop=$_POST['stop'];
$description=$_POST['description'];
$target_dir=“upload/”;
$target\u file=$target\u dir。basename($_文件[“图像”][“名称”]);
$uploadOK=1;
$imagetype=pathinfo($target\u文件,pathinfo\u扩展名);
如果(isset($_POST[“提交”])){
$check=getimagesize($_文件[“图像”][“tmp_名称]);
如果($check!==false){
echo“文件是图像-”$check[“mime”]。”;
$uploadOK=1;
}否则{
echo“文件不是图像。”;
$uploadOK=0;
}
}
如果(文件_存在($target_文件)){
echo“抱歉,文件已存在。”;
$uploadOK=0;
}
如果($_文件[“图像”][“大小”]>5000000){
echo“对不起,文件太大了。”;
$uploadOK=0;
}
如果($imagetype!=“jpg”&&$imagetype!=“jpeg”&&&$imagetype!=“png”&&$imagetype!=“gif”){
echo“对不起,只允许使用JPEG、JPG、PNG和GIF。”;
$uploadOK=0;
}
如果($uploadOK==0){
echo“未能上载。”;
}否则{
如果(移动上传的文件($文件[“图像”][“tmp文件名”],$目标文件)){
$query=mysql_query(“插入到anidata(id、title、image、genre、start、stop、description)值(‘$title’、‘$id’、‘$target_file’、‘$genre’、‘$start’、‘$stop’、‘$description’);
$uploadOK=1;
如果($query){
标题(“Location:view.php”);
}否则{
echo“上传失败””;
}
}
}
非常感谢您的帮助,谢谢:)您的查询值的顺序似乎不正确($id和$title应该是相反的)。改变这一点
$query=mysql\u query(“插入到anidata(id、title、image、genre、start、stop、description)值(“$title”、“$id”、“$target\u file”、“$genre”、“$start”、“$stop”、“$description”)代码>
对此,
$query=mysql\u query(“插入到anidata(id、title、image、genre、start、stop、description)值(“$id”、“$title”、“$target\u file”、“$genre”、“$start”、“$stop”、“$description”)代码>
还要确保变量类型与表中的字段一致(例如,不要试图将字符串保存在整数所在的位置)。在新代码中。它们不再得到维护,而是在使用。学习准备好的语句,然后使用or。没问题。如果答案解决了你的问题,请接受。