本文介绍了使用PHP和MySQL上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用php上传图像并将其保存在将接受其不同扩展名(例如bmp,jpeg等)的mysql数据库中.通过使用以下代码,一些上传的图像显示不完整.
I am trying to upload image using php and save in mysql database that would accept the different extension of it such as bmp, jpeg etc. By using the following codes, some of the uploaded images displayed incomplete.
这是uploadForm:
This is the uploadForm:
<html>
<form method="post" action="updateImage1.php" enctype="multipart/form-data">
<table border=0>
<tr>
<td><center><img src="getImage.php?id='.$row["No"].'" width=250 height=180/></center><br>
<input type="file" name="s4"><br>
<input name="update" type="submit" id="update" value="Save Changes" class="btn btn-primary" >
   
</form><a href="admin3.php"><button type="button" class="btn btn-primary">Cancel</button></a>
</tr>
</table>
</html>
这是updateImage1.php:
This is the updateImage1.php:
<?php
$s1 = addslashes(file_get_contents($_FILES['s4']['tmp_name']));
$host="localhost";
$user_name="root";
$database_name="5r";
$db=mysql_connect($host, $user_name,'');
if (mysql_error() > "") echo mysql_error() . "<br>";
mysql_select_db($database_name, $db);
if (mysql_error() > "") echo mysql_error() . "<br>";
$query = "UPDATE tblMain SET images='$s1' WHERE No=3";
$qresult = mysql_query($query);
echo "<script>alert('Records Successfully Updated'); location.href='admin3.php';</script>";
?>
这是getImage.php:
This is the getImage.php:
<?php
$No = $_GET['id'];
$link = mysql_connect("localhost", "root", "");
mysql_select_db("5r");
$sql = "SELECT images FROM tblMain WHERE No=$No";
$result = mysql_query("$sql");
$row = mysql_fetch_assoc($result);
mysql_close($link);
header("Content-type: image/jpeg/bmp/png");
echo $row['images'];
?>
推荐答案
将图像的数据类型更改为 Long Blob .
这篇关于使用PHP和MySQL上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!