[PHP] Directory Listing
Hi gang, I'm trying to create a script to read the files in a folder (approx 2000) and get the filename, path and last modified date in a tabulated format to copy into excel. (We have been issued a CD and need to get all files documented and assigned to an owner.) I've tried loads of different scripts but can't get them working with all the features. I think the best one to work with is this (although I'm having problems getting the date but don't worry about that at the moment) ? error_reporting(E_ALL); ini_set('display_errors', true); function getDirectory($path = '.', $ignore = '') { $dirTree = array (); $dirTreeTemp = array (); $ignore[] = '.'; $ignore[] = '..'; $dh = @opendir($path); while (false !== ($file = readdir($dh))) { if (!in_array($file, $ignore)) { if (!is_dir($path/$file)) { $dirTree[$path][] = $file; } else { $dirTreeTemp = getDirectory($path/$file, $ignore); if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp); } } } closedir($dh); return $dirTree; } $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota'); $dirTree = getDirectory('./Tender', $ignore); ? pre ? print_r($dirTree); ? /pre ?php getdirectory('./Tender'); //or //get_dir_iterative(/*etc.*/); ? Here is an example of what I'm getting out from the $dirTree array: Array ( [./Tender] = Array ( [0] = 9216_100_REV_V1.0_bound.dwg ) [./Tender/Tender Docs] = Array ( [0] = BAA Works Terms v1.1 (22.05.08).pdf [1] = Contents of Volumes 1 and 2.pdf [2] = Cover Letter and Instructions.doc [3] = Form of Tender.doc ) [./Tender/Tender Docs/Health and Safety Questionnaire] = Array ( [0] = NT Baggage Tender Questionaire rev2.xls ) [./Tender/Tender Docs/NTB BH Lighting] = Array ( [0] = 3J-B-1 PIR.xls [1] = 3J-B-2B PIR.xls [2] = 3J-B-2R PIR.xls [3] = 3J-B-3R PIR.xls [4] = 3J-D PIR.xls [5] = 4G-G PIR.xls [6] = 4J-B-1B PIR.xls [7] = 4J-B-1R PIR.xls [8] = 4J-B-2B PIR.xls [9] = 4J-B-2R PIR.xls [10] = 4J-B-4 PIR.xls [11] = 5G-G PIR.xls ) I'm having problems getting my head round how to get access the array data so that I can format it how I want, eg: Folder Filename Tender 9216_100_REV_V1.0_bound.dwg Tender/Tender Docs BAA Works Terms v1.1 (22.05.08).pdf Tender/Tender Docs Contents of Volumes 1 and 2.pdf etc. I'm trying to do this at work (php is a hobby and this is the first time I've tried to use it in my electrical engineering job) in notepad without any code highlighting, etc. and tearing my hair out to try and avoid going through the CD manually! Could anybody please help or let me know which function I need to read up on? I've tried countless searches on array formatting, etc and not getting anywhere. Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] directory listing from text file
Hello, I have a plain text file with the following direcory listing: \first \second \third \third\first \third\first\first \third\first\second \third\second \third\second\first \third\second\second \fourth How can I get directory tree from this and using Javascript or DHTML display such view: * first * second * third |---first ||---first ||---second |--(+)second * fourth I tried creating very interesting arrays, but don't know how exactly an array should be sorted Any ideas? Bye, Dreiph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] directory listing from text file
Dreiph, If you're familiar with PEAR, take a look at this: http://pear.php.net/package/HTML_TreeMenu regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] directory listing from text file
Thank you Chris, but this is not I needed. Let me explain my situation. I have a big server with a lot of audio files, working within LAN, with Windows 2000 Pro on it. Let's call it as FileServer. Also I have another server with Apache2 and PHP installed, windows 2000 PRO too, let's say it is WebServer. Web Server is standalone with two NIC cards, firewall, etc. I don't want to make Fileserver be accessible form Internet. The problem is that PHP and/or Apache on WebServer does not understand mapped drives from a FileServer, so readdir() or opendir() is not working correctly, by the way, it looks like Windows dir command works a little bit faster than readdir(); It take me some time to play with simple Windows command line utility, to get directory listing on FileServer and deliver plain text file to a WebServer. Command line was the following: exec('cmd /c dir /b /s /d /a:d \\\FileServer\\audiofiles audiofiles.txt'); $hi = fopen(audiofiles.txt, r); $line = fread($hi,filesize(audiofiles.txt)); fclose($hi); $line=explode(\n, $line); At this point I've got FileServer directories [only directories, not files!] scanned into file audiofiles.txt and this file was written to a WebServer. So, I have plain text file with correct directory structure, including subdirectories. The problem is, that dir command in Windows command prompt scans directories in weird format - each directory in new line, eg: \first \second \second\first \second\second \third I immagine, to show directory tree, I need to make some like array in PHP, and I think, this should be a recursive function [could not find out how to write it]. So final variable should be array like this: $directories = Array('\\first', '\\second = Array('\\first', '\\second'), '\\third'); How?? Thanks, Bye, Dreiph Chris Ramsay [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dreiph, If you're familiar with PEAR, take a look at this: http://pear.php.net/package/HTML_TreeMenu regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] directory listing from text file
What I know about Windows mapped drives could fit in a matchbook with room for every Playmate's phone number... But the answer I always hear when people are trying to do what you are trying to do is Samba HTH On Wed, May 18, 2005 7:37 am, dreiph said: Thank you Chris, but this is not I needed. Let me explain my situation. I have a big server with a lot of audio files, working within LAN, with Windows 2000 Pro on it. Let's call it as FileServer. Also I have another server with Apache2 and PHP installed, windows 2000 PRO too, let's say it is WebServer. Web Server is standalone with two NIC cards, firewall, etc. I don't want to make Fileserver be accessible form Internet. The problem is that PHP and/or Apache on WebServer does not understand mapped drives from a FileServer, so readdir() or opendir() is not working correctly, by the way, it looks like Windows dir command works a little bit faster than readdir(); It take me some time to play with simple Windows command line utility, to get directory listing on FileServer and deliver plain text file to a WebServer. Command line was the following: exec('cmd /c dir /b /s /d /a:d \\\FileServer\\audiofiles audiofiles.txt'); $hi = fopen(audiofiles.txt, r); $line = fread($hi,filesize(audiofiles.txt)); fclose($hi); $line=explode(\n, $line); At this point I've got FileServer directories [only directories, not files!] scanned into file audiofiles.txt and this file was written to a WebServer. So, I have plain text file with correct directory structure, including subdirectories. The problem is, that dir command in Windows command prompt scans directories in weird format - each directory in new line, eg: \first \second \second\first \second\second \third I immagine, to show directory tree, I need to make some like array in PHP, and I think, this should be a recursive function [could not find out how to write it]. So final variable should be array like this: $directories = Array('\\first', '\\second = Array('\\first', '\\second'), '\\third'); How?? Thanks, Bye, Dreiph Chris Ramsay [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dreiph, If you're familiar with PEAR, take a look at this: http://pear.php.net/package/HTML_TreeMenu regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] directory listing
Hi php-general, I'm reading through the filesystem function of php and I can't find any function which will list me all the files which are in a certain directory. Am I blind or do I have to create myself one? Thanks for help M. W. -- Who is the ennemy? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] directory listing
Wrong place, look at directory functions ;) Matthias Wulkow wrote: Hi php-general, I'm reading through the filesystem function of php and I can't find any function which will list me all the files which are in a certain directory. Am I blind or do I have to create myself one? Thanks for help M. W. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] directory listing
Hi! I have one question. How can I get sorted listing of a direcorty with readdir function? Is this possible or I have to write custom function using array function sort? TNX LP, AlesL -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] directory listing
On Thursday 09 January 2003 16:29, Ale Lonar wrote: Hi! I have one question. How can I get sorted listing of a direcorty with readdir function? Is this possible No, not with readdir() on its own. or I have to write custom function using array function sort? Yes, that is what you would have to do. Check out the user notes on the online manual. I think someone has posted some code that you can use or adapt. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* One has to look out for engineers -- they begin with sewing machines and end up with the atomic bomb. -- Marcel Pagnol */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory Listing with php on unix boxes
Here is where I'm running into some problems. I need the file listing to be sorted as if I were performing an 'ls -lt' listing on the server itself. I do not think opendir() or readdir() quarantees any sort. You where lucky rather you got dirs in the time order. You should use filemtime() or something like this to sort dirs. -- Krzysztof Dziekiewicz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Directory Listing with php on unix boxes
I have 3 SunOS boxes, all running the same version of OS, apache and php. I have a page on all three servers that will allow a user to select a directory from a drop down box and upon selecting the directory, be able to select a file to view from a drop down box. When the user selects the directory, the page is refreshed and a second drop down box containing the file names is displayed. Here is where I'm running into some problems. I need the file listing to be sorted as if I were performing an 'ls -lt' listing on the server itself. I'm using the readdir() function to get the file names and load them into an array. I then walk down the array backwards to build my drop-down list. On 2 of my servers, this method works great! However, on the other one, it is throwing the most recently created files in the middle of the list. Here is the code that I'm using: $handle=opendir($path); while (false !== ($file = readdir($handle))) $filenames[] = $file; for($i=(count($filenames) - 1); $i = 0; $i--) { $selected = ( $cboListFiles == $filenames[$i] ? selected : ); if ($filenames[$i] != . and $filenames[$i] !=..) { echo option value=. $filenames[$i] . $selected . $filenames[$i] . /option\n; } } Even if I take out the sorting, the file listing order does not change. Any ideas about what may be causing this? Thanks! Joe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Directory Listing with php on unix boxes
I have 3 SunOS boxes, all running the same version of OS, apache and php. I have a page on all three servers that will allow a user to select a directory from a drop down box and upon selecting the directory, be able to select a file to view from a drop down box. When the user selects the directory, the page is refreshed and a second drop down box containing the file names is displayed. Here is where I'm running into some problems. I need the file listing to be sorted as if I were performing an 'ls -lt' listing on the server itself. I'm using the readdir() function to get the file names and load them into an array. I then walk down the array backwards to build my drop-down list. On 2 of my servers, this method works great! However, on the other one, it is throwing the most recently created files in the middle of the list. Here is the code that I'm using: $handle=opendir($path); while (false !== ($file = readdir($handle))) $filenames[] = $file; for($i=(count($filenames) - 1); $i = 0; $i--) { $selected = ( $cboListFiles == $filenames[$i] ? selected : ); if ($filenames[$i] != . and $filenames[$i] !=..) { echo option value=. $filenames[$i] . $selected . $filenames[$i] . /option\n; } } Even if I take out the sorting, the file listing order does not change. Any ideas about what may be causing this? Thanks! Joe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Directory Listing with php on unix boxes
I have 3 SunOS boxes, all running the same version of OS, apache and php. I have a page on all three servers that will allow a user to select a directory from a drop down box and upon selecting the directory, be able to select a file to view from a drop down box. When the user selects the directory, the page is refreshed and a second drop down box containing the file names is displayed. Here is where I'm running into some problems. I need the file listing to be sorted as if I were performing an 'ls -lt' listing on the server itself. I'm using the readdir() function to get the file names and load them into an array. I then walk down the array backwards to build my drop-down list. On 2 of my servers, this method works great! However, on the other one, it is throwing the most recently created files in the middle of the list. Here is the code that I'm using: $handle=opendir($path); while (false !== ($file = readdir($handle))) $filenames[] = $file; for($i=(count($filenames) - 1); $i = 0; $i--) { $selected = ( $cboListFiles == $filenames[$i] ? selected : ); if ($filenames[$i] != . and $filenames[$i] !=..) { echo option value=. $filenames[$i] . $selected . $filenames[$i] . /option\n; } } Even if I take out the sorting, the file listing order does not change. Any ideas about what may be causing this? Thanks! Joe - Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now
[PHP] Directory Listing and File Reading errors
I'm recursivley reading and editing every .htm and .html file in a 500 page website and upgrading it to contain linked CSS, Javascript includes and PHP includes. i can't use a pre_pend file as there's more than one website on the server, and the changes are embedded in the document rather than just the header/footer. the script works fine and all, trouble is that PHP doesn't. Sometimes the script will run fine, other times PHP will decide to read the same file 10-20 times and then do the same for everyfile in certain directories. it's really annoying as some changes will be made over and over and over, also with 500 files being read 5-10 times each, the page times out after about 5000 reads... is this a PHP bug? or an Microsoft bug? or something else... i'm running PHP verson 4.0.4pl1 off a 2000 server and IIS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Directory Listing in an Array
Hey all, Just something I havent been able to sort out in the archives, but what im wanting to do it this. Do a listing of all files in a directory, and load up an array with each returned filename. Am I pissing into a windy pipe dream or is there a simple solution for this ? Cheers Chris -- Chris Aitken - Administration/Database Designer - IDEAL Internet email: [EMAIL PROTECTED] phone: +61 2 4628 fax: +61 2 4628 8890 __-__ *** Big Brother *** It just shows that the dull will rule the world. And we will be watching it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Directory Listing in an Array
Just something I havent been able to sort out in the archives, but what im wanting to do it this. Do a listing of all files in a directory, and load up an array with each returned filename. $files_dir = /tmp; chdir($files_dir); $dir_handle = @opendir($files_dir) or die(Unable to open $files_dir); $files = array(); while ($file = readdir($dir_handle)) { array_push($files, $file); } closedir($dir_handle); sort($files); reset($files); for ($i = 0; $i count($files); $i++) { echo $files[$i] br; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Directory Listing in an Array
This is what I use file://DIR to start looking in $basedir = C:/Inetpub/wwwroot/_ActiveClientFiles/GLS/portfolio/; file://working DIR or the dir to change to. $wdir = web/; // list of DIRs var $dirlist; $filelist; $add_dir ; /*** *** // Load Online Directorys **/ chdir($basedir . $wdir.'online/'); file://open the dir $online=opendir(.); while ($files = readdir($online)) { if(is_dir($files) ( $files !== . $files !== .. ) ) { $online_dir[$files] = $files; file://add files } } if(count($online_dir)) file://sort { asort($online_dir); } rewinddir($online); closedir($online); ? - Original Message - From: Chris Aitken [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, August 20, 2001 8:05 PM Subject: [PHP] Directory Listing in an Array Hey all, Just something I havent been able to sort out in the archives, but what im wanting to do it this. Do a listing of all files in a directory, and load up an array with each returned filename. Am I pissing into a windy pipe dream or is there a simple solution for this ? Cheers Chris -- Chris Aitken - Administration/Database Designer - IDEAL Internet email: [EMAIL PROTECTED] phone: +61 2 4628 fax: +61 2 4628 8890 __-__ *** Big Brother *** It just shows that the dull will rule the world. And we will be watching it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] directory listing and how to determine file size
I am going to develop virtual file management. Thus I want to know some things. 1. how to determine file size _before_ file uploading or on loading time and how to avoid error message if file size will be too large. You can't determine file size before uploading... *MAYBE* with some funky JavaScript?... 2. how to read directory content with it's size, modes etc in win32 and linux. win32 doesn't have modes, really... 3. in what mode i should make directory for read/write permission (not execute). Any point to docs? man chmod 4. Any other useful points to my project? I don't know all problems for it. Allowing surfers to upload arbitrary files is inherently dangerous. Be very, very careful. Just because a file isn't executable doesn't make it "safe". EG: If you let them upload a readable file that they can trick the browser into showing, and it contains PHP (or Perl, or JSP) code, they can execute *that*, even though it's not executable. I'm sure there are many, many other potential holes. -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] directory listing and how to determine file size
Hi, I am going to develop virtual file management. Thus I want to know some things. 1. how to determine file size _before_ file uploading or on loading time and how to avoid error message if file size will be too large. 2. how to read directory content with it's size, modes etc in win32 and linux. 3. in what mode i should make directory for read/write permission (not execute). Any point to docs? 4. Any other useful points to my project? I don't know all problems for it. TIA, -- Andris mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Directory Listing with PHP
(Damn I hate it when I forget to change the subject) Does anyone have, or know of a script which simulates what Apache gives out when it shows the entire contents of a directory ? I find it very handy to use the directory listing of say graphics directories and the like, but I dont want others looking into them. What I thought would be a good system is to have an index.php file which asks for a password. If the password is accepted, it shoots them off to a php script which displays the contents of the DIR just as apache would. This way I can bar viewing of the directories contents, only viewable to the owners of the password. Ive seen a couple of scripts which claim to show the directory listing, but none of them seem to work any good with a decent layout and amount of file info. So im looking for a script which can display the listing properly. Does one exist, or am I just relieving myself into the wind ? Thanks Chris -- Chris Aitken - Webmaster/Database Designer - IDEAL Internet email: [EMAIL PROTECTED] phone: +61 2 4628 fax: +61 2 4628 8890 Unix -- because a computer's a terrible thing to waste! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Directory Listing with PHP
You might like to try WebExplorer, may do what you want. http://suneworld.com/programs/ hth Regards Andrew Braund -Original Message- From: Chris Aitken [mailto:[EMAIL PROTECTED]] Sent: Thursday, 1 February 2001 15:35 To: PHP User Group Subject: [PHP] Directory Listing with PHP (Damn I hate it when I forget to change the subject) Does anyone have, or know of a script which simulates what Apache gives out when it shows the entire contents of a directory ? I find it very handy to use the directory listing of say graphics directories and the like, but I dont want others looking into them. What I thought would be a good system is to have an index.php file which asks for a password. If the password is accepted, it shoots them off to a php script which displays the contents of the DIR just as apache would. This way I can bar viewing of the directories contents, only viewable to the owners of the password. Ive seen a couple of scripts which claim to show the directory listing, but none of them seem to work any good with a decent layout and amount of file info. So im looking for a script which can display the listing properly. Does one exist, or am I just relieving myself into the wind ? Thanks Chris -- Chris Aitken - Webmaster/Database Designer - IDEAL Internet email: [EMAIL PROTECTED] phone: +61 2 4628 fax: +61 2 4628 8890 Unix -- because a computer's a terrible thing to waste! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]