首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >站点根目录上的成员图片

站点根目录上的成员图片
EN

Stack Overflow用户
提问于 2012-02-10 01:19:30
回答 1查看 71关注 0票数 1

我正在制作会员的管理数据库。我想把所有的会员图片放在网站根上面,这样他们就不能通过网址访问,但我想在会员资料上显示会员的照片。我正在使用php。我怎么能这么做呢?!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-10 01:38:06

您可以创建一个php文件,根据一些输入参数读取该文件,同时根据某些条件决定是否允许访问者查看该文件。

如下所示(简化示例):

代码语言:javascript
运行
复制
<?php

// presuming this file is in the root of your site
// define some directory where the actual images are
$dir = realpath( dirname( __FILE__ ) . '/../profile-images' );


// presuming this file is called with something like
// image.php?profileImage=fireeyedboy.jpg
if( isset( $_GET[ 'profileImage' ] ) )
{
    // strip all possible redundant paths
    // you should probably sanitize even more (check valid extensions etc.)
    $profileImage = basename( $_GET[ 'profileImage' ] );

    if( $someConditionsThatVisitorIsAllowedToViewThisImageAreMet )
    {
        // presuming mime type jpeg for now
        header( 'Content-Type: image/jpeg' );
        readfile( $dir . '/' . $profileImage );
        exit();
    }
    else
    {
        // conditions are not met, dish out HTTP/1.1 403 Forbidden header
        header( 'HTTP/1.1 403 Forbidden', true );
        exit();
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9215586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档