donglin8467 2014-07-16 13:42 采纳率: 0%
浏览 78
已采纳

如何从目标读取文件到变量?

I am trying to read a file's content, while doing something like this

$con="HDdeltin";
$fp = fopen($_SERVER['DOCUMENT_ROOT']. "/HDdeltin/Users/$con", "r");
echo $fp;

It doesn't return anything. What am I doing wrong?

  • 写回答

4条回答 默认 最新

  • duancui19840401 2014-07-16 13:49
    关注

    Fast solution :

    file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/HDdeltin/Users/HDdeltin");
    

    Use file_get_contents(), and you can prevent bad url with realpath().

    $con = "HDdeltin";
    $path = realpath($_SERVER['DOCUMENT_ROOT'] . "/HDdeltin/Users/$con");
    echo file_get_contents($path);
    

    To get current root, you can also use :

    See more :

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?