duanchun6148 2013-12-30 18:15
浏览 23
已采纳

网站root不是php安装root

This is section of code that I have put in /pgen/admin

<h1><b>List of saved text files:</b></h1>
<?php
$directory = "/pgen/saves/";
$phpfiles = glob($directory . "*.html");
$id = 1;

foreach ($phpfiles as $phpfile) {
    $date = " last modified/date created: " . date ("F d Y H:i:s.", filemtime($phpfile));
    echo $id.". <a href=$phpfile>".basename($phpfile)."</a>" .$date."<br>";
    $id ++;
}
?>

The $directory variable is supposed to be the root of the webpage plus /pgen/saves/. I have tried using $_SERVER["DOCUMENT_ROOT"]."/pgen/saves". Also, if I browse using a ftp client, it shows this page is located at /public_html/pgen/admin/ because I am using a 3rd party hosting service. The code is supposed to list the files in the /pgen/saves folder but the code itself is in the /pgen/admin folder. I've searched everywhere and since I'm new at php, I don't know what to do.

  • 写回答

1条回答 默认 最新

  • doulian4467 2013-12-30 18:24
    关注

    You would be better off to add some error checking/validation to your efforts. When using a foreach() method on an array, you must be aware that it is trusting you to pass it a legit array. If the value passed is not an array, it will try to use it and fail.

    $directory = "/pgen/saves/";
    $phpfiles = glob($directory . "*.html");
    $id = 1;
    
    // Error if no files are found
    if (!is_array($phpfiles) && count($phpfiles) <= 0) {
        die('no files found');
    }
    
    // Otherwise, continue on
    foreach ($phpfiles as $phpfile) {
        $date = " last modified/date created: " . date ("F d Y H:i:s.", filemtime($phpfile));
        echo $id.". <a href=$phpfile>".basename($phpfile)."</a>" .$date."<br>";
        $id ++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果