Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.