1

为了保证用户图像的安全,我将它们存储在 webroot 之外,并在附加的“image.php”脚本中通过 id 检查来调用它们。该脚本如下所示。

session_start();
require("scripts/sqlconnect.php"); 
$id = $_SESSION['id'];
$img = $_GET['id'];
$img = stripslashes($img);
$img = strip_tags($img);
$sql = mysql_query("SELECT * FROM photos WHERE id='$id'");   
$salt = mysql_query("SELECT * FROM members WHERE id='$id'");
$salt = mysql_fetch_array($salt);
$salt = $salt['salt'];
while($row = mysql_fetch_assoc($sql)){
    $imgfp = $row['filepath'];
    if(hash('sha256', $imgfp.$salt)==$img){
        $data = getimagesize($imgfp);
        if(!$data){
            header('HTTP/1.0 403 Forbidden');
            die('The file you requested is not an image.');
        }
        header('Content-type: ' .$data['mime']);
        header('Content-length: ' .filesize($imgfp));
        readfile($imgfp);
    }
}

我遇到的问题是使用 FancyBox 和这样的脚本。当我链接到这些图像(如下所示)时,FancyBox 无法工作,它只是直接链接到图像。有没有人有使用 FancyBox 或类似脚本的经验来满足这种调用图像的方法?

<a class="fancybox" rel="'.$relgroup.'" href="image?id='.$photofp.'" title="'.$pinfo.'"><img class="tnail" src="'.$tnail.'" /></a>

为 FancyBox 添加的 onload js 是这样的:

$(".fancybox")
    .fancybox({
        padding : 0,
        'scrolling' : 'no',
        helpers : {
            title   : {
            type: 'outside'
            },
        }
    });
4

1 回答 1

1

在上面的评论中,我在肯尼迪国际机场的帮助下弄清楚了这一点。

我创建了一个新类.fancyboximg,并将图像类型与开篇文章中所述的原始 onload 更改一起添加到该类中。

图像现在可以根据需要在 FancyBox 中打开!

$(".fancyboximg")
.fancybox({
    'type' : 'image',
    padding : 0,
    'scrolling' : 'no',
    helpers : {
        title   : {
        type: 'outside'
        },
    }
});
于 2012-10-10T16:44:33.053 回答