0

我在下面有一个表格,其中列出了每个问题的每个图像。

    <table id="tableqanda" cellpadding="0" cellspacing="0">
        <thead>
        <tr>
            <th width="5%" class="questionno">Question No.</th>
            <th width="11%" class="image">Image</th>
        </tr>
        </thead>
        </table>
        <div id="tableqanda_onthefly_container">
        <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
        <tbody>
            <?php
              foreach ($arrQuestionId as $key=>$question) {
            echo '<tr class="tableqandarow">'.PHP_EOL
echo '<td width="5%" class="questionno">'.htmlspecialchars($arrQuestionNo[$key]).'</td>' . PHP_EOL;
            echo '<td width="11%" class="imagetd">';
            if (empty($arrImageFile[$key])) {
                echo '&nbsp;';
            } else {
                echo '<ul class="qandaul"><li>';
                echo implode("</li>\n<li>", array_map(function($imgitem){
                return htmlspecialchars($imgitem);
            },  $arrImageFile[$key]));
                echo '</li></ul>';
            }
            echo '</td>';
            echo '</tr>'.PHP_EOL;
            }
    ?>
        </tbody>
        </table>
        </div>

现在它只是在项目符号列表中列出图像文件名。但我想做的是我想将每个文件设置为超链接,这样如果用户单击图像链接,它将在单独的页面中显示该图像(将打开一个单独的窗口)显示图像本身

我的问题是如何做到这一点,我需要执行以下哪些步骤?如果有人可以告诉我如何逐步编码,那么我也可以将它用于音频和视频。

谢谢

4

3 回答 3

1

Okay, I've been thinking about what you want to do and I think you want to show a list of images as thumbnails or something, and then click an image and show it (within your layout) on a new page (previewimage.php).

You have a lot of options... but they all boil down to passing some information through the URL (example.com/previewimage.php).

First, let's examine 2 typical ways to pass information through an URL

$_GET Request

Sometimes you'll see a website pass add information to a URL, like

example.com/previewimage.php?var=xxx

This allows you to pass some information to your PHP script via the $_GET superglobal.

Htaccess

If you want to get kind of fancy, you can use htaccess to make a clean URL

RewriteRule ^([a-zA-Z0-9]+)/$ previewimage.php?var=$1

This will let you have an URL like example.com/xxx and the server will act like you went to example.com/previewimage.php?var=xxx.

Now that you know how to hand information off to the url, we can look into some methods for using the $_GET['var'] to show the image.

The easiest approach is to simply pass the name of the file... for this example let's call it example.png.

If you're using the basic $_GET Request method above, you would have an URL like example.com/previewimage.php?var=example.png.

Then, in previewimage.php, you simply do something like

<img src="<?php echo $_GET['var'] ?>"/>

This will output

<img src="example.png"/>

However, this is not a very safe method, as anyone can load anything they want. A better option might be using an array or a database, and then passing a key of some sort and retrieving the filename.

I think this will set you on the right path (and I hope it answers your question).

于 2013-01-26T18:14:55.097 回答
0

假设这个问题是如何在新选项卡中打开链接。用这个包围你喜欢的任何东西,在这种情况下是图像。

<a href="/linktoimage.png" target="_blank"><img src="/linktoimage.png" alt="my image"></a>
于 2013-01-26T17:32:54.220 回答
0

这是如何做到这一点的示例。刚刚对内部“If else”循环进行了编辑

将 YOUR_BASE_URL_FOR_IMAGES_HERE_ENDING_WITH_A_DASH 替换为服务器上图像的目录路径。

if (empty($arrImageFile[$key])) {
    echo '&nbsp;';
} else {
    echo '<ul class="qandaul"><li>';
    echo implode("</li>\n<li>", array_map(function($imgitem) {
                        return '<a href="YOUR_BASE_URL_FOR_IMAGES_HERE_ENDING_WITH_A_DASH' . htmlspecialchars($imgitem) . '" target="_blank">' . htmlspecialchars($imgitem) . '</a>';
                    }, $arrImageFile[$key]));
    echo '</li></ul>';
}
于 2013-01-26T17:54:39.320 回答