marcus Posted November 21, 2006 Share Posted November 21, 2006 How would I do about listing files in a directory? Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/ Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Look at the [url=http://www.php.net/glob]glob()[/url] function.Ken Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128114 Share on other sites More sharing options...
marcus Posted November 21, 2006 Author Share Posted November 21, 2006 There isn't any other way? Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128116 Share on other sites More sharing options...
realjumper Posted November 21, 2006 Share Posted November 21, 2006 http://www.phpit.net/code/list-files-directory/ Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128117 Share on other sites More sharing options...
marcus Posted November 21, 2006 Author Share Posted November 21, 2006 Is it possible to like list files of another website? Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128120 Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 The question is ..... What are you trying to accomplish?Ken Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128122 Share on other sites More sharing options...
marcus Posted November 21, 2006 Author Share Posted November 21, 2006 To be able to list files from my site to show on my other website. Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128123 Share on other sites More sharing options...
Seraskier Posted November 21, 2006 Share Posted November 21, 2006 What you could do is make it display files on that website and then make a iframe to the file that displays the files. Heres the code to display what is in a database:[code]<?echo ("<h1></h1>");function getFiles($path) { //Function takes a path, and returns a numerically indexed array of associative arrays containing file information, //sorted by the file name (case insensitive). If two files are identical when compared without case, they will sort //relative to each other in the order presented by readdir() $files = array(); $fileNames = array(); $i = 0; if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file == "." || $file == ".." || $file == "index.php") continue; $fullpath = $path . "/" . $file; $fkey = strtolower($file); while (array_key_exists($fkey,$fileNames)) $fkey .= " "; $a = stat($fullpath); $files[$fkey]['size'] = $a['size']; if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-"; else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K"; else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb"; else $files[$fkey]['sizetext'] = $a['size'] . " bytes"; $files[$fkey]['name'] = $file; $files[$fkey]['type'] = filetype($fullpath); $fileNames[$i++] = $fkey; } closedir($dh); } else die ("Cannot open directory: $path"); } else die ("Path is not a directory: $path"); sort($fileNames,SORT_STRING); $sortedFiles = array(); $i = 0; foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f]; return $sortedFiles;}$files = getFiles("./");foreach ($files as $file) print " <b><a href=\"$file[name]\">$file[name]</a></b><br>\n";?>[/code] Link to comment https://forums.phpfreaks.com/topic/28009-listing-files-in-directory/#findComment-128128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.