每当我在网站上动态显示图像时,图像图标都会损坏。可能是什么问题?
这是我的插入按钮代码:
<?php
if(isset($_POST['insert_post'])){
//getting the text data from the fields
$product_title = $_POST['product_title'];
$product_cat= $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting the image from the field
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = file_get_contents($_FILES['product_image']['tmp_name']);
$imagetype=$FILES['product_image']['type'];
$array=array('jpg','jpeg','png');
$ext=pathinfo($product_image,PATHINFO_EXTENSION);
if(!empty($product_image)){
if(in_array($ext,$array)){
}
else{
echo "unsupported format";
}
}
else{
echo "please select the image";
}
move_uploaded_file($product_image_tmp,"product_images/$product_image");
$insert_product="insert into products (product_cat,product_brands,product_title,product_price,product_desc,product_image,product_keywords)
values('$product_cat','$product_brand ','$product_title','$product_price','$product_desc','$product_image','$product_keywords') ";
$insert_pro=mysqli_query($conn, $insert_product);
if($insert_pro){
echo "<script>alert('product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self'</script>";
}
}
功能页代码:
function getPro(){
global $conn;
$get_pro="select * from products order by RAND() LIMIT 0,6";
$run_pro=mysqli_query($conn, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id=$row_pro['product_id'];
$pro_cat=$row_pro['product_cat'];
$pro_brand=$row_pro['product_brands'];
$pro_title=$row_pro['product_title'];
$pro_price=$row_pro['product_price'];
$pro_image=$row_pro['product_image'];
echo "
<div id='single_product'>
<h3> $pro_title </h3>
<img src='adminarea/product_images/$pro_image' width='200';height='200';/>
<p><b style='float:right; padding:5px;'> price: ksh $pro_price</b></p>
<a href='details.php ?pro_id=$pro_id'style='float:left; padding:5px;'>Details</a>
<a href='index.php ?add_cart=$pro_id'><button style='float:right; padding:5px;'>Add to Cart</button></a>
</div> ";
}
我怀疑问题可能出在
<img src='adminarea/product_images/$pro_image' width='200';height='200';/>
因为图像已成功插入数据库,但是当我在网站页面上显示它们时,我收到了损坏的图像图标。