这是我的PHP脚本,它显示一个电台的时间表:

    <div class="divider"></div>
    <div class="main" style="width:552px;">
        <img src="$image" width=115 height=60>
        <div class="time">$airtime</div>
        <div class="show"><h3><a href="$link><b>$presenter</b></a></h3>
            <p>$showdesc</p></div>
        <div class="footer"></div>
    </div>
    </div>
                <div class="footer"></div>
                <div class="bottom"></div>
            </div>

带美元符号的值表示数据库中的字段名,该数据库是radiopresenters。
如何使它作为一个PHP脚本工作,并显示数据库中的值?
字段中的所有值都以文本格式存储,而图像字段则以BLOB格式存储。
Airtime存储在一个名为radioschedule的单独数据库中,该数据库包含所有4个字段ib,我打算通过一些相关的方式将这些字段链接在一起。
什么是最好的方式让它显示为上述,特别是BLOB部分?

最佳答案

您要做的是设置一个show_image.php脚本,例如
显示图像.php

<?php
$id = (isset($_GET['blid']) && is_numeric($_GET['blid'])) (int)$_GET['blid'] : false;

if($id)
{
    if(false !==($res = mysql_query('SELECT blob_data FROM table WHERE blob_id = ' . $id))
    {
        $data = mysql_fetch_assoc($res);
        header("Content-type: image/jpg"); //Send the content Type here.
        print $data['blob_data'];
        exit;
    }
}
?>

然后在html文件中执行以下操作。
<div class="divider"></div>
<div class="main" style="width:552px;">

    <img src="show_image.php?id=<?php echo (int)$id?>" width=115 height=60>

    <div class="time">$airtime</div>
    <div class="show">
        <h3><a href="$link><b>$presenter</b></a></h3>
        <p>$showdesc</p></div>
        <div class="footer"></div>
    </div>
</div>
<div class="footer"></div>
<div class="bottom"></div>

大致就是这样做的,另一个指针是当您通过主页选择数据时,您不应该选择blob数据,因为它会减慢应用程序的速度,s how_image.php可能需要更多的工作,因为它只用于示例目的
和平。

关于php - 在PHP脚本中显示BLOB文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3713253/

10-10 21:43
查看更多