回显显示为 URL 的图像文件


echoing image files that are being displayed as urls

正如此页面显示的那样 https://armoredwarfareleagues.com/PvE_February_Results.php 它显示了我想查看的表信息,但图像文件仅显示URL。在脚本中,我将上传的图像复制到新文件夹并重新调整为 100x100。这一切都很好。我正在尝试做的是将此图像以 100x100 格式显示在新文件夹中的表格中,使其成为在灯箱中以全尺寸打开原始文件的链接。我真的是一个菜鸟,并且通过跟踪和错误完成了这一切,但我在这个网站上发现了什么。其中很多我只是不明白。我需要帮助来完成这个项目。只是说添加此功能超出了我,因为我不知道在哪里添加它。上传文件的原始文件夹是"上传",带有调整大小的图像的新文件夹是"uploadtn" 如何让名为 url 的数据库从新文件夹中回显?如何使回显的图像成为原始图像的链接?如何使其在灯箱中全尺寸打开?原始文件大小设置为 500KB 或更小。新文件大小约为 5-7KB。

<?php
echo "<table style='border: solid 1px black;'>";
echo "<th>Team Name</th><th>Team Captian</th><th>Total Damage</th><th>Best 1</th><th>Best 2</th><th>Best 3</th><th>Best 4</th><th>Best 5</th></tr>";
class TableRows extends RecursiveIteratorIterator { 
    function __construct($it) { 
        parent::__construct($it, self::LEAVES_ONLY); 
    }
    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }
    function beginChildren() { 
        echo "<tr>"; 
    } 
    function endChildren() { 
        echo "</tr>" . "'n";
    } 
} 
$servername = "localhost";
$username = "********_pvedama";
$password = "*********";
$dbname = "********_pvedamage";
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare("SELECT username, fullname, damage, FILEUPLOAD1, FILEUPLOAD2, FILEUPLOAD3, FILEUPLOAD4, FILEUPLOAD5  FROM tdamage"); 
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
        echo $v;
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

我认为您将网址显示为文本。 你正在这样做

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) 
{ 
   echo $v;
}

取而代之的是,您必须在图像 SRC 中打印 URL,如下所示:

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
    echo $v[0];  //for team name
    echo $v[1];  // for Team Captian
    echo $v[2]; // for Total Damage
    echo '<img src=".$v[3].">'; // for Best 1--- image
    echo '<img src=".$v[4].">'; // for Best 2--- image
}