gpt4 book ai didi

php - 如何插入图片?

转载 作者:行者123 更新时间:2023-11-30 23:48:44 25 4
gpt4 key购买 nike

以下是我的代码文件...我无法插入图像。出现错误,Undefined variable: image

<html>
<head>
<title> Upload an image </title>
</head>
<body>
<form action="image-disp.php" method="post" enctype="multipart/form-data">
File:
<input type="file" name="image" value=iamge><br>
<input type="submit" value="Upload">
</form>
<?php
mysql_connect("localhost", "root", " ") or die(mysql_error());
mysql_select_db("mysql") or die(mysql_error());
echo "connected";
if (!isset($_FILES['image'] ['tmp_name'])) {
echo "Choose an image";
} else {
echo $image = addslashes($_FILES['image'] ['tmp_name']);
echo $image_name = addslashes($_FILES['image']['name']);
echo $image_size = getimagesize($_FILES['image'] ['tmp_name']);
}
if ($image_size = FALSE) {
echo "It's not an image";
} else {
$result = "INSERT INTO testblob (image_id, image, image_size) "
. "VALUES (' ' ,'$image', '$image_size')";
}
echo "inserted";
?>
</body>
</html>

最佳答案

最好只在数据库中保存图像的名称,而在某个文件夹中保存文件

$result = "INSERT INTO testblob ( image, image_size) 
VALUES ('$image_name', '$image_size')";

然后你像那样检索它:

<img src="path/<?php echo $row['image_name'];?>">

关于php - 如何插入图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22588873/

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