[英]Uploading a file (image) doesn't work on live server but works on dev
[英]Uploading the image file to the server doesn't work
我试图将带有准备好的语句的 BLOB 上传到 MYSQL 数据库,但我找不到它不起作用的原因。 有人可以向我解释原因吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registrieren</title>
</head>
<body>
<header>
<?php
if (isset($_POST['submit'])) {
require_once "db_connect.php";
//Arbeit mit prepared Statements, da diese gegen SQL-Injections sicher sind im Gegensatz zum Escapen
$stmt = $mysqli->prepare("INSERT INTO Bild (Bild_ID, Inhalt, Info) VALUES (?, ?, ?)");
$stmt->bind_param("ibs", $picID, $image, $info);
// set parameters and execute
$picID = NULL;
$image = file_get_contents($_FILES['userPic']['name']);
echo($image);
$info = "just an example";
$stmt->execute();
echo "New records created successfully";
$stmt->close();
$mysqli->close();
}
?>
</header>
<main>
<form action="" method="post" enctype="multipart/form-data">
<input id="UserPicUpload" type="file" name="userPic" accept="image/*">
<button id="send" type="submit" name="submit" >Bild Hochladen</button>
</form>
</main>
</body>
</html>
这里有几个错误...
image
和picID
和info
。tmp_name
键获得。 关于 picID:根据用例,您可以在数据库中将其设置为AUTO_INCREMENT
。 由于类型是整数,我怀疑您是否真的想手动设置这些数字。
这会给我们留下以下代码:
$image = file_get_contents($_FILES['userPic']['tmp_name']);
$info = "just an example";
$stmt = $mysqli->prepare("INSERT INTO Bild (Inhalt, Info) VALUES (?, ?)");
$stmt->bind_param("bs", $image, $info);
$stmt->execute();
echo "New records created successfully";
另一个词:将您的东西命名为德语或英语并在全球范围内使用,但不要混淆语言。 将Bild_ID
命名为picID
是相当混乱的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.