简体   繁体   中英

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. 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? Have you tried Copying URL and linked directly to it from your browser? If the URL is coming back blank, try $row instead of $_FILES since you are just wanting the path to the file.

This line is wrong: $img = "uploads/" . $_FILES["file"]["name"]; $img = "uploads/" . $_FILES["file"]["name"]; .

Replace it with $img = "uploads/" . $row[x]; $img = "uploads/" . $row[x]; where x is the number of column where file name is

OR

with $img = "uploads/" . $row['columnname']; $img = "uploads/" . $row['columnname']; . Here you have to replace columnname .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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