我試圖使用表單將圖像上傳到數據庫。未上傳到數據庫的php圖像
問題是,當我嘗試上傳圖像時,它不存儲在數據庫中。也沒有錯誤。
在此先感謝。
<html>
<head>
<meta charset="UTF-8" />
<title>Images</title>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image" />
<input type="submit" value="Upload" />
</form>
<?php
require "connect.inc.php";
@$file = $_FILES['image']['tmp_name'];
if (!isset($file)) {
echo "Please select an image.";
}
else {
$image = file_get_contents($_FILES['image']['tmp_name']);
$imageName = $_FILES['image']['tmp_name'];
$imageSize = getimagesize($_FILES['image']['tmp_name']);
if ($imageSize == FALSE) {
echo "This is not an image.";
}
else {
$sql = "INSERT INTO `afbeelding` VALUES ('', '$imageName', '$image')";
if (!mysql_query("INSERT INTO `afbeelding` VALUES ('', '$imageName', '$image')")) {
echo "Problem uploading image.";
}
else {
echo "Succes!";
}
}
}
?>
</body>
</html>
這應該對你有所幫助。 http://stackoverflow.com/questions/17717506/how-to-upload-images-into-mysql-database-using-php-code – momouu
你想上傳,圖像或只是爲了將名稱保存到數據庫? –
我只是想通了。來自monaca19的鏈接顯示addslashes,並以某種方式增加了工作。 – IvoryNL