How to display the list of files stored in the folder on the server using php and making a call to that php page using ajax so as to display the list of files to the user on the client machine?
A very simple example:
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>
精彩评论