简体   繁体   English

PHP的显示图像从存储路径?

[英]php displaying image from stored path?

UPDATE. 更新。

I can only display the images inside a query eg 我只能在查询中显示图像,例如

if($Result = mysqli_query($Link, $Query)){
while($row = mysqli_fetch_array($Result))
{
$img = $row['path'];
echo '<img src="'.$img.'">'; 
}
}

I want to display them inside a table but this code doesn't work : 我想将它们显示在表中,但是此代码不起作用:

<td class="tcgimagecell" colspan="5"><?php echo '<img src="'.$img.'">'; ?></td>

BELOW ISSUE RESOLVED : 解决的问题如下:

I have images stored in a folder (uploads) and the path is stored in a database table in a field named path. 我将图像存储在文件夹中(上载),并且路径存储在数据库表中名为path的字段中。 I am trying to display the stored images. 我正在尝试显示存储的图像。

$Link = mysqli_connect($Host, $User, $Password, $Database);
$Query = "SELECT * FROM $images";

if($Result = mysqli_query($Link, $Query)){
while($row = mysqli_fetch_array($Result))
{
$img = "uploads/" . $_FILES["file"]["name"];
echo '<img src="'.$img.'">';
}
}

Your folder permissions for "uploads/" might not be set to public read. 您对“上载/”的文件夹权限可能未设置为公开读取。 Have you checked those already? 你已经检查过了吗? What is the URL that is output for your image? 您的图像输出的URL是什么? Have you tried Copying URL and linked directly to it from your browser? 您是否尝试过复制URL并直接从浏览器链接到它? If the URL is coming back blank, try $row instead of $_FILES since you are just wanting the path to the file. 如果URL重新变空,请尝试$ row而不是$ _FILES,因为您只需要文件的路径。

This line is wrong: $img = "uploads/" . $_FILES["file"]["name"]; 这行是错误的: $img = "uploads/" . $_FILES["file"]["name"]; $img = "uploads/" . $_FILES["file"]["name"]; .

Replace it with $img = "uploads/" . $row[x]; 将其替换为$img = "uploads/" . $row[x]; $img = "uploads/" . $row[x]; where x is the number of column where file name is 其中x是文件名所在的列数

OR 要么

with $img = "uploads/" . $row['columnname']; $img = "uploads/" . $row['columnname']; $img = "uploads/" . $row['columnname']; . Here you have to replace columnname . 在这里,您必须替换columnname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM