duanjuan1103 2019-05-02 01:36
浏览 27

如何使用php在URL浏览器中加密和保护readdir()?

I have develop system to scan and read file inside folder.

And I stored all pdf file inside uploads folder inside root directory. Directory as below.

htdocs/test_system/uploads/test123.pdf

In my HTML, PHP and JQuery code, I already pass the test123.pdf into form value using jQuery as below.

<form action="" method="POST">
    <input id="filename_verify" type="hidden" class="form-control" name="filename_verify" placeholder="" value="test123.pdf" readonly="readonly"> 
    <button type="submit" id=""   name="verify" class="btn btn-success btn-block">Submit</button>                                                           
</form> 

My next step is to check whether the filename match with the database before user can open the file. PHP code as below.

if(isset($_POST['verify']))
{  
    $filename_verify    = $_POST['filename_verify'];

    $sql = DB::getInstance()->FetchArray("select filename from table where filename = '".$filename_verify."' ");
    if(count($sql) > 0)
    {
        foreach($sql as $row){}
        header("Location: uploads/".$filename_verify.""); 
    }
    else
    {
        echo 'Not match';
        exit;
    }   
}

I can open file successfully but the problem is URL obviously show the directory of the file like this so the publis can easily predict the directory and can manipulate the filename using URL.

https://www.system.com/uploads/test123.pdf 

How can I secure and encrypt the URL so the user cannot see the actual directory like above URL ?

Appreciate if someone can help me. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line