gpt4 book ai didi

PHP上传图片失败

转载 作者:行者123 更新时间:2023-12-05 00:29:30 25 4
gpt4 key购买 nike

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>

现在我想显示图片。但我一直得到一张空白图片。我那里的显示代码有问题吗?谢谢

/虚拟//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa//虚拟

最佳答案

在表单中添加 enctype="multipart/form-data"

<form method="post" action="test.php" enctype="multipart/form-data">

关于PHP上传图片失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37315588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com