Jump to content

Please help me specify a folder


Moron

Recommended Posts

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

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?

 

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)));

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!    ;D

 

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?

 

:)

 

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?

 

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.