【问题标题】:diplaying images from database in jQuery plugin: Galleriffic在 jQuery 插件中显示数据库中的图像:Galleriffic
【发布时间】:2011-04-15 05:42:50
【问题描述】:

我正在使用一个 jQuery 插件 - Galleriffic (link here)

我也在关注这个教程:Upload Files To Database

好的,图像现在在数据库中,但我无法使用以下方法查看数据库中的图像:

<img src="getpicture.php?fid=1">

我在这里错过了什么?

【问题讨论】:

    标签: php jquery database image


    【解决方案1】:

    您是否将标题设置为 header("Content-Type: image/jpeg")

    为了测试调用 URL

    getpicture.php?fid=1
    

    看看会发生什么?

    编辑:在第 5 步

    <?
    if(isset($_GET['fid']))
    {
    // connect to the database
    include "connect.php";
    
    // query the server for the picture
    $fid = $_GET['fid'];
    $query = "SELECT * FROM files WHERE fid = '$fid'";
    print $query;
    $result  = mysql_query($query) or die(mysql_error());
    print_r($result);
    
    // define results into variables
    $name=mysql_result($result,0,"name");
    $size=mysql_result($result,0,"size");
    $type=mysql_result($result,0,"type");
    $content=mysql_result($result,0,"content");
    print "check point 1 => $name, $size, $type, $content";
    // give our picture the proper headers...otherwise our page will be confused
    header("Content-Disposition: attachment; filename=$name");
    header("Content-length: $size");
    header("Content-type: $type");
    echo $content;
    
    mysql_close();
    }else{
    die("No file ID given...");
    }
    
    ?> 
    

    用上面的代码替换并从浏览器调用,看看它打印了什么?

    【讨论】:

    • 我已经按照你说的设置了header,我测试了url但是什么都没有出现
    【解决方案2】:

    getpicture.php

    1. 获取图片的id
    2. 查询数据库。
    3. 回显header("Content-Type: image/jpeg")之后的图像

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2013-08-21
      相关资源
      最近更新 更多