jakebur01 Posted January 6, 2009 Share Posted January 6, 2009 How do I read a list of files in a directory with php? example if I want to see all the excel, pdfs, etc in http://testsite.com/downloads/ I am creating a backend for a dealer downloads page. I want to be able to select the file and store the url to it in a database. Then, display the download files on our downloads page. Thanks, Jake Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/ Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 scandir, dir and or glob Those are the functions you want to look into. Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731068 Share on other sites More sharing options...
jakebur01 Posted January 6, 2009 Author Share Posted January 6, 2009 thank you.... Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731070 Share on other sites More sharing options...
jakebur01 Posted January 6, 2009 Author Share Posted January 6, 2009 Is it possible to list files in a directory across the web rather than on the local server. I am having trouble getting the code below to work. code: <?php /* ABOUT: This snippet will list all the files in the directory of your choice, truncate the file extension, capitalize the first letter and put it all in a drop down menu. The script will not list subdirectories so all you see are the files in your directory. Feel free to use or modify to your liking. USAGE: Change the $dirpath variable the directory you want to list. AUTHOR: Written by shockingbird Visit www.glomer.net for more information tate at tatenations dot com for any questions */ echo "<form>"; //Looks into the directory and returns the files, no subdirectories echo "<select name='yourfiles'>"; //The path to the style directory $dirpath = "http://mysite.com/downloads/"; $dh = opendir($dirpath); while (false !== ($file = readdir($dh))) { //Don't list subdirectories if (!is_dir("$dirpath/$file")) { //Truncate the file extension and capitalize the first letter echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>'; } } closedir($dh); //Close Select echo "</select>"; echo "</form>"; ?> error: PHP Warning: opendir(http://mysite.com/downloads/) [function.opendir]: failed to open dir: not implemented in C:\Inetpub\Websites\mysite.com\scan.php on line 25 PHP Warning: readdir(): supplied argument is not a valid Directory resource in C:\Inetpub\Websites\mysite.com\scan.php on line 26 PHP Warning: closedir(): supplied argument is not a valid Directory resource in C:\Inetpub\Websites\mysite.com\scan.php on line 33 Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731154 Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 Probably not, due to the fact if it is not setup to be displayed you cannot display it. If it is setup to be displayed you need to just fetch the page and parse out the link/file locations. Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731158 Share on other sites More sharing options...
jakebur01 Posted January 6, 2009 Author Share Posted January 6, 2009 By setup, do you mean permissions in iis? Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731166 Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 By setup, do you mean permissions in iis? Almost every website hides their directories cause the world does not need to see it. However, if their webserver is setup to show directories you will get an html page list of the directories. If they do not have that, you would have to have FTP permission to the site to get all the filenames etc. If they do not have it in a list somewhere, you cannot get their directory listing. Quote Link to comment https://forums.phpfreaks.com/topic/139733-selecting-files-in-a-directory/#findComment-731176 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.