golffor1 Posted August 7, 2011 Share Posted August 7, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.