Jump to content

Can't search files in another folder and open it


golffor1

Recommended Posts

So I have the following code.  It supposed to do 2 things....first thing it does it finds the newest file inside a folder.  This works perfectly

 

#2 it is suppose to open up that new file and display the contents.  This does not work.

 

<?
//The finds the newest file inside the directory
$dir = "../images/my_folder";
function compare($a,$b) {
  return $b[1] - $a[1];
}
$dir='../images/tournament_pics'; $max=1;
$files=Array();
$f=opendir($dir);
//$f=opendir("../images/tournament_pics/");
while (($file=readdir($f))!==false) {
  if(is_file("$dir/$file")) {
    $files[]=Array($file,filemtime("$dir/$file"));
  }
}
closedir($f);
usort($files,"compare");
$m=min($max,count($files));
for ($i=0;$i<$m;$i++) {
$newestfile = "{$files[$i][0]}\n";
$location = $dir.'/'.$newestfile;
//$dir = "http:/my_site/tournament_pics";
$location = $dir.'/'.$newestfile;
}
[b]$handle = fopen($location, 'r');[/b]
?>

 

The code is in a different folder than what the item I am looking for is in.  So there are 3 folders

1. Main folder

1a. documents folder--(inside the main folder)

1b. script folder --(inside the main folder also)

 

How do I tell PHP to look back 1-3 folders and find a file, and then open it without prompting a user to save the file.  The line in bold is where I think the error is.  Also when I tell it to display $location it displays the following result....        ../images/tournament_pics/newestfile.txt

 

Any suggestions on how to get this to work properly.

 

Thanks in advance for your help

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.