简体   繁体   English

PHP无法从我的服务器文件夹中获取图像

[英]PHP not fetching images from my server folder

I have this code that is supposed to fetch an image from my server and display it on my html. 我有应该从服务器获取图像并将其显示在html上的代码。 My images are encrypted in md5 and when uploading them to the server there is no field in my table that stores the names of the images. 我的图像在md5中加密,并且在将它们上传到服务器时,我的表中没有存储图像名称的字段。 I am therefore calling the image using the primary key in the table to get the image. 因此,我使用表中的主键调用该图像以获取图像。

Here is my code: 这是我的代码:

<?php
    // connection string constants
    define('DSN', 'mysql:dbname=mydbname;host=localhost');
    define('USER', 'myuser2015');
    define('PASSWORD', 'mypwd2015');

    // pdo instance creation
    $pdo = new PDO(DSN, USER, PASSWORD);

    // query preparation
    $stmt = $pdo->query("
        SELECT title, introtext, id, created, created_by, catid
        FROM mytbl_items LIMIT 4
    ");

    // fetching results
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // if this returns 0 then it means no records are present
    echo count($result) . "\n";

    // the loop should print valid table
    foreach ($result as $index => $row) {
        if ($index == 0) echo '<div>';
        echo <<<HTM
    <img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";




       <span class="post-date">{$row['created']}</span>

        <h2 class="blog-post-title">{$row['title']}</h2>
        <p>
            {$row['introtext']}
        </p>
        <p>

            <a href='read.php?id={$row['id']}'><input type="button" value="Read More" /></a>
        </p></br>
        <div class="blog-meta">
            <img src="img/icons/logo.png" alt="Avatar" />
            <h4 class="blog-meta-author">{$row['created_by']}</h4>
            <span>Category: {$row['catid']}</span>
        </div>
HTM;
        if ($index == (count($result)-1))echo '</div>';
    }

What mistake am I making with the code that is supposed to fetch the image? 我应该用来获取图像的代码犯了什么错误? This is the line 这是线

img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";

Remove second echo from your here/nowdoc. 从您的here / nowdoc中删除第二个echo显。 You already started echo ing in 您已经开始echo

echo <<<HTM

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

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