在我使用PHP从MySQL删除第一张图片之前,我无法上传第二张图片。当我上传图片时,显示的信息是“图片未上传”。在我从MySQL数据库中删除图像之前,会显示此消息。
我的代码:
<?php
ini_set('mysql.connect_timeout',300);
ini_set('default_socket_timeout',300);
?>
<html>
<body>
<form method="post" enctype="multipart/form-data">
<br/>
<input type="file" name="image"/>
<br/><br/>
<input type="submit" name="submit" value ="Upload"/>
</form>
<?php
if(isset($_POST['submit'])) {
if(getimagesize($_FILES['image']['tmp_name'])== FALSE) {
echo "Please Select an image" ;
}
else {
$image =addslashes($_FILES['image']['tmp_name']);
$name =addslashes($_FILES['image']['name']);
$image= file_get_contents($image);
$image= base64_encode($image);
saveimage($name,$image);
}
}
displayimage();
function saveimage($name,$image) {
$con=mysqli_connect("localhost","***","***");
mysqli_select_db($con,'images');
$qry="insert into images(name,image) values ('$name','$image')";
$result=mysqli_query($con,$qry);
if($result){
echo "<br/> Image uploaded.";
} else {
echo "<br/> Image not uploaded.";
}
}
function displayimage ()
{
$con=mysqli_connect("localhost","***","***");
mysqli_select_db($con,"images");
$qry="select * from images";
$result=mysqli_query($con , $qry);
while ($row = mysqli_fetch_array($result)) {
echo '<img height="300" width="300" src = "data:image;base64,'.$row[2].'">';
}
mysqli_close($con);
}
?>