comparing a files date script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
webguy
Forum Newbie
Posts: 7
Joined: Wed Nov 20, 2002 3:53 pm
Location: Kansas City, MO

comparing a files date script?

Post by webguy »

hello-

anyone have a script handy that will take a file passed to it, get the date of the file's creation and compare it vs. the current date?

I'm developing on a win98 box, but the script will run on a linux box.

basicaly I want to check a dir, and each file in it. then get the date of the file's creation compare it to the current date, the return valued of them being compared will be compared to a value stored in a db.

Any hints or clues on what functions I should check out or if anyone has a script similar to this already written, that would be great help to me.

thanks for your time!

- webguy
webguy
Forum Newbie
Posts: 7
Joined: Wed Nov 20, 2002 3:53 pm
Location: Kansas City, MO

Post by webguy »

justa bump... :D
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i don't believe you can get the creation date for a file (someone feel free to correct me if im wrong). the closet function that would seem to suit your purpose is the stat() function: http://www.php.net/manual/en/function.stat.php
webguy
Forum Newbie
Posts: 7
Joined: Wed Nov 20, 2002 3:53 pm
Location: Kansas City, MO

Post by webguy »

yeah I'm using the stat() function. but the problem I'm running into know is the date that is being returned is the date of a directory where the .php file is being run from. I added a is_file() check and it says I'm not getting any files for some reason. Although I can print out the names of the files, etc.

Here's my code:

Code: Select all

<?php 
$strWFOs = array("eax", "apx");
for ($i = 0; $i < 2; $i++)
&#123;
  //define the path
  $path = "/www/datascour/". $strWFOs&#1111;$i] ."/";
  //using the opendir function
  $dir_handle = @opendir($path) or die("Unable to open $path");
  echo "<pre>";
  echo "Directory Listing of $path\n";
  echo "<br /><br />\n";
  //running the while loop
  while ($file = readdir($dir_handle)) 
  &#123;
	  if ($file != "." && $file != "..") //getting rid of the ".'s"
	  &#123;
		  if (is_file($file)) //checking to see if there is a file
			  &#123;
				  if (strpos($file, "."))
				  &#123;
					$strPos =	strpos($file, ".");
					$fileName = substr($file, 0, $strPos); 
				  &#125;else&#123;
					$fileName = $file;
				  &#125;
				  $info = stat($filename);
				  echo date("d.M Y H:i:s", $info&#1111;'ctime'])." - ".$fileName ."<br />";
		      &#125;else&#123;
				  echo "error...file does not exist!<br />";
			  &#125;
		  clearstatcache();
		&#125;
	&#125;
  //closing the directory
  closedir($dir_handle);
  echo "</pre>";
&#125;
?>
any help on this would be appreciated

-webguy
Post Reply