2011-03-27 56 views
-2

如何使用php顯示存儲在服務器上的文件夾中的文件列表,並使用ajax調用該php頁面以便顯示文件列表客戶機上的用戶?需要php代碼來獲取服務器上存儲的文件列表

+2

這不是一個代碼工廠。請搜索本網站和您最喜愛的搜索引擎,並在您遇到具體問題時發佈。 – Mat 2011-03-27 15:07:03

+0

一個好的起點是:http://php.net/manual/en/function.scandir.php – JohnP 2011-03-27 15:17:32

+0

[擁抱非谷歌](http://meta.stackexchange.com/questions/5280/embrace-the -non-googlers),[禁止LMGTFY鏈接](http://meta.stackexchange.com/questions/15650/ban-lmgtfy-let-me-google-that-for-you-links) – 2011-03-27 15:32:00

回答

1

一個非常簡單的例子:

http://jfcoder.com/test/showfilesget.php

showfiles.php

<?php 

// open this directory 
$dir = opendir("files"); 

// get each entry 
while($file = readdir($dir)) { 
    if (substr($file, 0, 1) != '.') { 
     print "$file\n"; 
    } 
} 

// close directory 
closedir($dir); 

?> 

showfilesget.php

<script type="text/javascript"> 

$(document).ready(function(){ 
    $('#loadfiles').click(function(){ 
     $.get('http://jfcoder.com/test/showfiles.php', function(data) { 
      $('#files').html(data); 
     }); 
    }); 
}); 

</script> 

<h1>Loaded Files</h1> 
<pre id="files"></pre> 
<p><span class="link" id="loadfiles">Load files content</span></p> 
相關問題