Moron Posted June 27, 2007 Share Posted June 27, 2007 I have a routine where a user can put text files into a folder and the code will display the name of each file (minus the .txt extension) with the contents of the file below it. The PHP page resides in one folder, while the text files sit in a subfolder below that: <?php echo "<center>"; echo "<font size=\"5\" color=\"#000000\" face=\"times new roman\"><b>Page Title</b></font>"; echo "</center>"; echo "<center>"; echo "<font size=\"8\" color=\"#000000\" face=\"times new roman\"><b>Bid Requests</b></font>"; echo "<BR>"; echo "<BR>"; $extension = '.txt'; $blank = ''; echo "<font size=\"3\" color=\"#000000\" face=\"arial\">The following bid requests are open at this time:</font>"; echo "<BR>"; echo "<BR>"; echo "<font size=\"3\" color=\"#000000\" face=\"arial\">"; if ($handle = opendir('./bidfolder/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<center>"; echo "<b>"; echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))); echo "</b>"; echo "<BR><BR>"; readfile($file); echo "<BR><BR>"; echo "<img src='http://www.website/images/bidbar.jpg'>"; echo "<BR>"; echo "<BR>"; echo "</center>"; } } closedir($handle); echo "</font>"; } ?> The opendir function is pulling filenames from the folder, "bidfolder," as it should, BUT....the readfile function is looking in the root for file contents. I have to also have each text file in the root folder (mmbids) or it errors. In other words, how do I make the readfile function point to the "bidfolder" subfolder? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/ Share on other sites More sharing options...
Moron Posted June 27, 2007 Author Share Posted June 27, 2007 Bump. Anybody? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-283983 Share on other sites More sharing options...
Dragen Posted June 27, 2007 Share Posted June 27, 2007 try this: readfile($handle.$file); Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-283985 Share on other sites More sharing options...
Moron Posted June 27, 2007 Author Share Posted June 27, 2007 try this: readfile($handle.$file); No go. It gives me.... [function.readfile]: failed to open stream: No such file or directory in C:\user\WWWRoot\MMBids\bidrequest.php on line 45 It's working like it is, but I don't want the user to have to save the text files in both the mmbids folder and the bidfolder folder. It's pulling the file list from bidfolder but trying to read the text of the file from mmbids, where it doesn't exist. I need to redirect the "readfile" part to the bidflder folder. Make sense? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-283989 Share on other sites More sharing options...
Dragen Posted June 27, 2007 Share Posted June 27, 2007 sorry I think I did that wrong readfile('./bidfolder/' . $file); That should work, although you need to change this line as well echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))); to echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', './bidfolder/' . $file))); Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-283995 Share on other sites More sharing options...
Moron Posted June 27, 2007 Author Share Posted June 27, 2007 sorry I think I did that wrong readfile('./bidfolder/' . $file); That should work, although you need to change this line as well echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))); to echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', './bidfolder/' . $file))); 1. It works 2. You're awesome! I don't suppose you would also know an easy way to make it display them sorted by file date/time (newest on top) instead of alphabetically? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-284015 Share on other sites More sharing options...
Dragen Posted June 27, 2007 Share Posted June 27, 2007 hmm.. not really. To get the last modified date of a file though use this: $modified = filemtime('./bidfolder/' . $file); That will give you a time you can easily use with the date() function. Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-284029 Share on other sites More sharing options...
Moron Posted June 27, 2007 Author Share Posted June 27, 2007 hmm.. not really. To get the last modified date of a file though use this: $modified = filemtime('./bidfolder/' . $file); That will give you a time you can easily use with the date() function. I see. Yeah, that lists the date/time code for each file when I echo it. Anybody know how I can make it sort by this date/time code with newest on top? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-284086 Share on other sites More sharing options...
Moron Posted June 27, 2007 Author Share Posted June 27, 2007 Sorry to bump this again, but does anyone know how to sort this by date/time with newest first? Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-284120 Share on other sites More sharing options...
Dragen Posted June 27, 2007 Share Posted June 27, 2007 it's only been 30mins since you last asked. try doing it yourself and see what you get. I'd suggest using arrays to store all of the files along with the dates for them, then echo them out in order of date. Link to comment https://forums.phpfreaks.com/topic/57399-please-help-me-specify-a-folder/#findComment-284135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.