On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote:
> 2009/8/26 Ashley Sheridan <[email protected]>:
> > On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
> >> I've been playing about more and now I have the following code:
> >>
> >> <?
> >> error_reporting(E_ALL);
> >> ini_set('display_errors', true);
> >>
> >> function getDirectory($path = '.', $ignore = '') {
> >> $dirTree = array ();
> >> $dirTreeTemp = array ();
> >> $fileDate = array ();
> >> $ignore[] = '.';
> >> $ignore[] = '..';
> >> $dh = @opendir($path);
> >> while (false !== ($file = readdir($dh))) {
> >> if (!in_array($file, $ignore)) {
> >> if (!is_dir("$path/$file")) {
> >> $dirTree["$path"][] = $file;
> >> $fileDate["$file"][] = date ("d/m/Y",
> >> filemtime("$path/$file"));
> >> } else {
> >> $dirTreeTemp = getDirectory("$path/$file", $ignore);
> >> if (is_array($dirTreeTemp))$dirTree =
> >> array_merge($dirTree, $dirTreeTemp, $fileDate);
> >> }
> >> }
> >> }
> >> closedir($dh);
> >> return $dirTree;
> >> }
> >>
> >> $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
> >> $dirTree = getDirectory('.', $ignore);
> >> getdirectory('.');
> >>
> >> echo "Gatwick Tender Documents\n";
> >>
> >> foreach( $dirTree as $key => $folder ){
> >> echo "\n"; //Don't need folders as they're shown with the files
> >> foreach( $folder as $file){
> >> echo str_replace("./", "", $key) . "\t" . $file . "\t\n"; //Pad
> >> out with a tab for easy import into excel
> >>
> >> }
> >> }
> >> print_r($dirTree); //Just using this for debugging
> >> ?>
> >>
> >>
> >> The output is fine for the paths and filenames but I still can't get
> >> the dates showing. It's getting the correct date for some but not all.
> >> I did something else earlier and found that all the dates were
> >> 01/01/1970 but at least there was a date for every file but can't
> >> remember how I go there!
> >>
> >>
> >> Here is a sample output result:
> >>
> >> Gatwick Tender Documents
> >>
> >> . 9216_100_REV_V1.0_bound.dwg
> >>
> >> Tender Docs BAA Works Terms v1.1 (22.05.08).pdf
> >> Tender Docs Contents of Volumes 1 and 2.pdf
> >> Tender Docs Cover Letter and Instructions.doc
> >> Tender Docs Form of Tender.doc
> >>
> >> Tender Docs/Health and Safety Questionnaire NT Baggage Tender
> >> Questionaire rev2.xls
> >>
> >> BAA Works Terms v1.1 (22.05.08).pdf 29/07/2009
> >>
> >> Contents of Volumes 1 and 2.pdf 29/07/2009
> >>
> >> Cover Letter and Instructions.doc 29/07/2009
> >>
> >> Form of Tender.doc 29/07/2009
> >>
> >> Tender Docs/NTB BH Lighting 3J-B-1 PIR.xls
> >> Tender Docs/NTB BH Lighting 3J-B-2B PIR.xls
> >> Tender Docs/NTB BH Lighting 3J-B-2R PIR.xls
> >> Tender Docs/NTB BH Lighting 3J-B-3R PIR.xls
> >> Tender Docs/NTB BH Lighting 3J-D PIR.xls
> >> Tender Docs/NTB BH Lighting 4G-G PIR.xls
> >> Tender Docs/NTB BH Lighting 4J-B-1B PIR.xls
> >> Tender Docs/NTB BH Lighting 4J-B-1R PIR.xls
> >> Tender Docs/NTB BH Lighting 4J-B-2B PIR.xls
> >> Tender Docs/NTB BH Lighting 4J-B-2R PIR.xls
> >> Tender Docs/NTB BH Lighting 4J-B-4 PIR.xls
> >> Tender Docs/NTB BH Lighting 5G-G PIR.xls
> >>
> >>
> >> Can anyone shed any light on it?
> >> I'm about to admit defeat!
> >>
> >> Thanks in advance and I'm not being lazy - I really am trying!!! :(
> >>
> >> Tom
> >>
> >
> > The only time I've ever noticed this problem was on a 32bit system where
> > the files were above 2GB each. When the files are that size, none of the
> > information functions seem to work correctly, including the filesize,
> > date, etc.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> >
>
> Cheers Ash,
> I read that too, but I was getting the error for over 90% of the files
> which I know are generally only a few MB.
> I've started from scratch again and come up with something that is
> easier to deal with but still having one last problem!
>
> <?php
> error_reporting(E_ALL);
> ini_set('display_errors', true);
> function directoryToArray($directory, $recursive) {
> $array_items = array();
> if ($handle = opendir($directory)) {
> while (false !== ($file = readdir($handle))) {
> if ($file !="index.php" && $file != "." && $file !=
> "..") {
> if (is_dir($directory. "/" . $file)) {
> //For Directories
> if($recursive) {
> $array_items =
> array_merge($array_items,
> directoryToArray($directory. "/" . $file, $recursive));
> }
> $fullfile = $directory . "/" . $file;
> $array_items[] =
> preg_replace("/\/\//si", "/", $fullfile);
> } else {
> //For Files
> $fullfile = $directory . "/" . $file;
> $array_items[] =
> preg_replace("/\/\//si", "/", $fullfile);
> }
> }
> }
> closedir($handle);
> }
> return $array_items;
> }
>
> $files = directoryToArray("./Tender", true);
>
>
> //Output to browser
> foreach ($files as $file) {
> echo str_replace("./Tender", "", $file) . "\t" . " " . date
> ("d/m/Y",
> filemtime($file)) . "\n";
> }
> //print_r($files);
> ?>
>
>
> The output I'm getting is:
> /9216_100_REV_V1.0_bound.dwg 05/08/2009
> /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf 29/07/2009
> /Tender Docs/Contents of Volumes 1 and 2.pdf 29/07/2009
> /Tender Docs/Cover Letter and Instructions.doc 29/07/2009
> /Tender Docs/Form of Tender.doc 29/07/2009
> /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender
> Questionaire rev2.xls 29/07/2009
> /Tender Docs/Health and Safety Questionnaire 14/08/2009
> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-D PIR.xls 13/05/2009
>
> All I need to do now is get a tab between the filename & the path
> I'm thinking I need to explode on the "/" and somehow match the last
> value but stumped at the moment!
>
>
> Tom
>
You could do a substr on $file:
$filename = substr($file, strrpos('/')+1);
$directory = substr($file, 0, strlen($file) - strrpos('/'));
I've not tested that, so you might need to adjust slightly a character
position here or there.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php