Php 如何处理损坏的图像图标?
每当我在网站中动态显示图像时,我都会收到损坏的图像图标。有什么问题吗 这是我的插入按钮代码:Php 如何处理损坏的图像图标?,php,html,Php,Html,每当我在网站中动态显示图像时,我都会收到损坏的图像图标。有什么问题吗 这是我的插入按钮代码: <?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
<?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>";
}
}
如何准确输出图像?从数据库中读取并正确输出的代码在哪里?width='200';高度='200'代码>不是有效的HTML。请确保您的图像存在于该位置,并且您的服务器可以读取这些图像。您可能需要使用开发人员控制台(F12)并查看错误。您好,NIco我有用于输出图像的功能。您的图像是否上载到您想要的文件夹?
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';/>