liamloveslearning Posted September 4, 2009 Share Posted September 4, 2009 Hi everyone, not sure if this is in the right board but im sure its php scripting what I need. A client of mine wants her users to be able to view a list of files uploaded to a certain directory in order for them to download as opposed to uploading them to the server and manually typing links for members to download, s what i need is a web based file browser which automatically pulls all of the files from the directory and lists them for the members to download, Sorry if this makes no sense but I cant find anything anywhere? Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 We were working on this earlier today, I believe. http://www.phpfreaks.com/forums/index.php/topic,267895.0.html I'll assume you can implement that code? By the way, I don't know what happened in my last post on that thread. I C&P'd, and obviously it messed up my formatting. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted September 4, 2009 Share Posted September 4, 2009 Take a look at glob It's prob the easiest way to show files in a certain directory Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted September 4, 2009 Share Posted September 4, 2009 Open a handle to the directory and loop through the files to display. If the directory contains sub-directories you require a recursive function. Checkout the examples on php.net http://uk3.php.net/opendir Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted September 4, 2009 Author Share Posted September 4, 2009 Sorry im not too fluent with php and so a lot of this is going over my head, ive tried reading up on the glob() function but it doesnt seem to do anything when i implement it, where i have <?php foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; } ?> how do i tell this script to show all files in /members directory? Thanks for your help Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted September 4, 2009 Author Share Posted September 4, 2009 would this work? <?php $dir = "/members"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2009 Share Posted September 4, 2009 <?php foreach (glob("/members/*") as $filename) { echo $filename . "<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted September 4, 2009 Author Share Posted September 4, 2009 thanks for your help thorpe, still no luck however. Im just reading php manual now, would opendir, scan dir and closedir codes work? (sorry if that makes no sense im really new to this) Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2009 Share Posted September 4, 2009 What do you mean still no luck? My code would list all files within /members Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted September 4, 2009 Author Share Posted September 4, 2009 Its just nothing is showing up, Im most probably missing something, but theres files in my members directory and nothing outputting on my page, my current page looks like this... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta name="verify-v1" content="JjQqYu4Jx1GcPAbjGwq8XVbkpxptsdhffIC+qnlyFU8=" /> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <script src="js/prototype.js" type="text/javascript"></script> <script src="js/scriptaculous.js?load=effects,builder" type="text/javascript"></script> <script src="js/lightbox.js" type="text/javascript"></script> <META name="description" content="Ann Summers Parties in North West, Runcorn, Widnes and surrounding areas"> <META name="keywords" content="Ann Summers, Parties, Party, manchester, oldham, salford, wigan, stockport, girl night in, hen night"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Anne Summers Anywhere 2009</title> <!-- InstanceEndEditable --> <link href="images/style.css" rel="stylesheet" type="text/css" /> <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> </head> <body> <div id="browser"> <div id="wrapper"> <div id="header"> <img src="images/hdr.png" /> </div> <div id="nav"> <ul id="tctopnav"> <li class="first"> <a href="index.html">Welcome</a></li> <li> <a href="hostess.html">Become a hostess</a></li> <li> <a href="jointeam.html">Join our team</a></li> <li> <a href="hostessoffers.html">become an organiser</a></li> <li> <a href="areas.html">areas</a></li> <li> <a href="about.html">about us</a></li> <li> <a href="contact.html">contact</a></li> <li> <a href="members/index.html">Members area</a></li> <li><a href="gallery.html">Gallery</a></li> <li class="last"><a href="links.html">links</a></li> </ul> <img src="images/JOIN.jpg" alt="d" width="210" height="103" border="0" usemap="#Map2" /> <map name="Map2" id="Map2"><area shape="rect" coords="5,7,205,97" href="jointeam.html" /> </map> <img src="images/heart.png" width="171" height="104" border="0" usemap="#Map" /> <map name="Map" id="Map"><area shape="rect" coords="6,6,167,98" href="jointeam.html" /> </map><br /> <br /> </div> <!-- InstanceBeginEditable name="C ontent" --> <div id="content"> <?php foreach (glob("/members/*") as $filename) { echo $filename . "<br />"; } ?> </div> <!-- InstanceEndEditable --> <div id="footer"> <a href="index.html">Welcome</a> / <a href="hostess.html">Become a hostess</a> / <a href="team.html">Join our team</a> / <a href="hostessoffers.html">Become an organiser</a> / <a href="areas.html">Areas</a> / <a href="about.html">About us</a> / <a href="contact.html">Contact</a> / <a href="links.html">Links</a><br /> © 2009 Ann Summers Anywhere | Website design and Development by <a href="http://www.reloaddesign.co.uk" target="_blank">Reload Design</a></div> </div> </div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-10030192-1"); pageTracker._trackPageview(); } catch(err) {}</script> </body> <!-- InstanceEnd --></html> Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2009 Share Posted September 4, 2009 /members is likely not the correct path. Try... foreach (glob("members/*") as $filename) { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.