【问题标题】:Member Pictures above site root网站根目录上方的会员图片
【发布时间】:2012-02-09 17:19:29
【问题描述】:

我正在制作会员的管理数据库。我想将所有成员图片放在站点根目录上方,以便无法通过 url 访问它们,但我想在成员个人资料中显示成员的图片。我正在使用 php。我怎样才能做到这一点?!谢谢!

【问题讨论】:

    标签: php root


    【解决方案1】:

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

    类似这样的东西(简化示例):

    <?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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-31
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多