文件夹中的图像不会显示在php页面中

时间:2022-01-06 00:23:41

i have an ecommerce website and the admin can upload contents with images and the images will upload to a folder the problem here is that the images from the folder wont display in the page.

我有一个电子商务网站,管理员可以上传带有图像的内容,图像将上传到文件夹,这里的问题是文件夹中的图像不会显示在页面中。

this the code ( a function that will display the content with their images )

这个代码(一个用它们的图像显示内容的函数)

function getPro(){
global $con;
$get_pro="select * from products order by RAND() LIMIT 0,6";
$run_pro=mysqli_query($con,$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_brand'];
    $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='/Applications/XAMPP/xamppfiles/htdocs/ecommerce/admin_area/product_images/$pro_image' width='180' height='180'/>
</div>";
}
}

and also i tried an image from the web the same problem the image wont show. this is what it display not showing

而且我也尝试从网络上的图像同样的问题图像不会显示。这是显示不显示的内容

1 个解决方案

#1


-1  

The first Note is that any variable through the single quotations are not detected. You should rewrite the variable out of it. Second, If images are in the exact folder that your code exists,then you just need to replace your current src value with only "$pro_image".

第一个注意事项是未检测到通过单引号的任何变量。你应该重写变量。其次,如果图像位于代码所在的确切文件夹中,那么您只需要用“$ pro_image”替换当前的src值。

Therefore you sholud rewrite this code:

所以你sholud重写这段代码:

echo " 
<div id='single_product'>
<h3> $pro_title </h3>
<img src='./" + $pro_image + "' width='180' height='180'/>
</div>";

Edit: If the location of images and html file are different, you should enter the relative address between your images and your html file. For example your image files are in a folder that this folder is in the parent folder of your html file, you can write the address like this: src="../foo/image.jpg" I've used "../" to locate parent folder. Please check the last comment I told the exact src address. I hope it was useful.

编辑:如果图像和html文件的位置不同,则应输入图像与html文件之间的相对地址。例如,您的图像文件位于此文件夹位于html文件的父文件夹中的文件夹中,您可以像这样编写地址:src =“../ foo / image.jpg”我用过“../ “找到父文件夹。请检查我告诉确切的src地址的最后一条评论。我希望它很有用。

#1


-1  

The first Note is that any variable through the single quotations are not detected. You should rewrite the variable out of it. Second, If images are in the exact folder that your code exists,then you just need to replace your current src value with only "$pro_image".

第一个注意事项是未检测到通过单引号的任何变量。你应该重写变量。其次,如果图像位于代码所在的确切文件夹中,那么您只需要用“$ pro_image”替换当前的src值。

Therefore you sholud rewrite this code:

所以你sholud重写这段代码:

echo " 
<div id='single_product'>
<h3> $pro_title </h3>
<img src='./" + $pro_image + "' width='180' height='180'/>
</div>";

Edit: If the location of images and html file are different, you should enter the relative address between your images and your html file. For example your image files are in a folder that this folder is in the parent folder of your html file, you can write the address like this: src="../foo/image.jpg" I've used "../" to locate parent folder. Please check the last comment I told the exact src address. I hope it was useful.

编辑:如果图像和html文件的位置不同,则应输入图像与html文件之间的相对地址。例如,您的图像文件位于此文件夹位于html文件的父文件夹中的文件夹中,您可以像这样编写地址:src =“../ foo / image.jpg”我用过“../ “找到父文件夹。请检查我告诉确切的src地址的最后一条评论。我希望它很有用。