dongnaigu2052 2012-06-02 22:17
浏览 32
已采纳

如何编写php脚本来更新文件列表? [关闭]

i have a program to update some file from my site and i do all work but i have a problem in update.php script

my application side update cod is(in C#):

    public string[] NeededFiles = { "teknomw3.dll" };
    public string HomePageUrl = "http://se7enclan.ir";
    public string NewsUrl = "http://se7enclan.ir/news";
    public string DownloadUrl = "http://se7enclan.ir/";
    public string UpdateList = "http://se7enclan.ir/update.php?action=list";
    public string UpdateBaseUrl = "http://se7enclan.ir/Update/";

and my update directory on my site as you see(all files is here.):

http://se7enclan.ir/Update/

so what script must be in update.php that i can use this: "update.php?action=list"

this update.php script must work like this site: http://mw3luncher.netai.net/update.php?action=list

Thank you.

  • 写回答

1条回答 默认 最新

  • doukuipei9938 2012-06-02 22:47
    关注

    I understand your problem man. Here is a solution:

    <?PHP
      function getFileList($dir)
      {
        // array to hold return value
        $retval = array();
    
        // add trailing slash if missing
        if(substr($dir, -1) != "/") $dir .= "/";
    
        // open pointer to directory and read list of files
        $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
        while(false !== ($entry = $d->read())) {
          // skip hidden files
          if($entry[0] == ".") continue;
          if(is_dir("$dir$entry")) {
            $retval[] = array(
              "name" => "$dir$entry/",
              "type" => filetype("$dir$entry"),
              "size" => 0,
              "lastmod" => filemtime("$dir$entry")
            );
          } elseif(is_readable("$dir$entry")) {
           $retval[] = array(
              "name" => "$dir$entry",
              "type" => mime_content_type("$dir$entry"),
              "size" => filesize("$dir$entry"),
              "lastmod" => filemtime("$dir$entry")
            );
          }
       }
        $d->close();
    
        return $retval;
      }
    ?>
    

    You can use this function as follows:

    <?PHP
      // examples for scanning the current directory
      $dirlist = getFileList(".");
      $dirlist = getFileList("./");
    ?>
    

    And to output the results to an HTML page we just loop through the returned array:

    <?PHP
      // output file list as HTML table
      echo "<table border="1">
    ";
      echo "<tr><th>Name</th><th>Type</th><th>Size</th><th>Last Mod.</th></tr>
    ";
      foreach($dirlist as $file) {
        echo "<tr>
    ";
        echo "<td>{$file['name']}</td>
    ";
        echo "<td>{$file['type']}</td>
    ";
        echo "<td>{$file['size']}</td>
    ";
        echo "<td>",date('r', $file['lastmod']),"</td>
    ";
        echo "</tr>
    ";
      }
      echo "</table>
    
    ";
    ?>
    

    Hope it helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan