Re: Problem with filemtime

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi  Joe , 
I may be wrong, this is what i understood from your msg .
You need to get a list of files from a directory right ?

This code may help you if you are looking for this , 

//Starts Here

//Put here the directory you want to search for. Put / if you want to search your entire domain

$dir='/';



//Put the date you want to compare with in the format of:  YYYY-mm-dd hh:mm:ss

$comparedatestr="2006-08-12 00:00:00";

$comparedate=strtotime($comparedatestr);



//I run the function here to start the search. 

directory_tree($dir,$comparedate);



//This is the function which is doing the search...

function directory_tree($address,$comparedate){ 



 @$dir = opendir($address); 



  if(!$dir){ return 0; } 

        while($entry = readdir($dir)){ 

                if(is_dir("$address/$entry") && ($entry != ".." && $entry != ".")){                             

                        directory_tree("$address/$entry",$comparedate);

                } 

                 else   {



                  if($entry != ".." && $entry != ".") {

                  

                    $fulldir=$address.'/'.$entry;

                    $last_modified = filemtime($fulldir);

                    $last_modified_str= date("Y-m-d h:i:s", $last_modified);



                       if($comparedate < $last_modified)  {

                          echo $fulldir.'=>'.$last_modified_str;

                          echo "<BR>";

                       }



                 }



            }



      } 



}

Hari K T

http://www.harikt.com/
http://ijust4u.blogspot.com/


--- On Thu, 12/3/09, Joe Forsythe <jforsythe@xxxxxxxxxxxxxxxxxx> wrote:

From: Joe Forsythe <jforsythe@xxxxxxxxxxxxxxxxxx>
Subject:  Problem with filemtime
To: php-objects@xxxxxxxxxxxxxxx, phpexperts@xxxxxxxxxxxxxxx
Date: Thursday, 12 March, 2009, 8:18 PM











    
            I'm doing dynamic generation of a Google sitemap. The important  

(albeit truncated) code is as follows:



$file_list = get_sitemap( $directory, $file_list) ; # Function that  

loops through the site and gets all of the file names

$file_list = explode('|', $file_list) ; # The list of files is pipe (|)  

separated

array_pop($file_ list); # The last array value is blank because of the  

way the loop in the function above works



for ($i=0;$i<count( $file_list) ;$i++) {

         echo $file_list[$ i].' .:. ';

         echo date ("F d Y H:i:s.", filemtime('. ./about- 

us.html')).' .:. TEST<br />'; # The ../ is because this file is  

running in a subdirectory and for proof of concept that it's working

         echo date ("F d Y H:i:s.", filemtime($file_ list[$i]) ).' .:.  

TEST<br />';

         echo date ("F d Y H:i:s.", filemtime('. ./about- 

us.html')).' .:. TEST<br />'; # The ../ is because this file is  

running in a subdirectory and for proof of concept that it's working

}



The problem is that when filemtime hits the *first* file in *any*  

directory, it bombs for that file, with this error:

Warning: filemtime() [function.filemtime ]: stat failed for [file name  

would be here]



A couple of notes:

1. The two '../about_us. html' lines are there to nail the first file  

it is trying to get the time from.

2. Doing filemtime with the file name directly typed into filemtime  

works fine.

3. I also did a string comparison on the directly typed name vs. the  

array version of the name, and they are *exactly* the same.

4. I tried doing file opens, directory opens, and pretty much  

anything else I could come up with to possibly "initialize" access to  

the various directories, but it didn't make any difference.

5. I googled and did my due diligence for filemtime and the error  

message, but

5. I also tried a bunch of canned scripts for generating Google  

sitemaps, but none of them really worked for my purposes.



Any insight any of you can provide is greatly appreciated.



If you've got a really good script that automatically grabs all file  

names, file mod times, and has a file ignore list, I'd love to see  

it. Like I said, nothing I found seemed to be very solid and didn't  

work very well.

--

Joe



[Non-text portions of this message have been removed]




 

      

    
    
	
	 
	
	








	


	
	


      Bring your gang together. Do your thing. Find your favourite Yahoo! group at http://in.promos.yahoo.com/groups/

[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux