test.php文件
<?php
if(isset($_POST['submit']))
{
if(getimagesize($_FILES['image']['tmp_name'])==FALSE)
{
echo "Please select an image";
}
else
{
$image = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
saveimage($image);
}
}
function saveimage($image)
{
$con=mysql_connect("localhost","root","");
mysql_select_db("food",$con);
$query = "INSERT INTO info(image) VALUES ('$image')";
$result = mysql_query($query,$con);
if($result)
{
echo "<br> Image upload";
}
else
{
echo "<br> NOT";
}
}
function displayimage()
{
$con=mysql_connect("localhost","root","");
mysql_select_db("food",$con);
$query = "SELECT image from info";
$result = mysql_query($query,$con);
$row=mysql_fetch_array($result);
echo '<img src="data:image/jpeg;base64,'.$row["image"].'" width="200" height="200"/>';
}
?>html文件
<form method="post" action="test.php">
<label>Image:</label>
<input type="file" name="image"><br>
<input class="btn btn-primary" type="submit" name="submit" value="Confirm" style="height:50px; width:100px;">
<br><br>
</form>现在我想展示这张照片。但我总是得到一张空白的照片。我的显示代码有什么问题吗?谢谢
/dummy//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa//dummy
发布于 2016-05-19 06:40:20
在表单中添加enctype="multipart/form-data"
<form method="post" action="test.php" enctype="multipart/form-data">发布于 2016-05-19 06:41:48
您的enctype="multipart/form-data"标记中缺少了form。
enctype属性指定将表单数据提交到服务器时应如何编码。
注意: enctype属性只能与method="post"一起使用。
发布于 2016-05-19 06:45:36
将enctype="multipart/form-data"添加到表单标记中。
https://stackoverflow.com/questions/37315588
复制相似问题