Help?!

Here are the two codes I’m trying out below:

[code]<?PHP

The current directory

$directory = dir("./NCFA/exports/");

If you want to turn on Extension Filter, then uncomment this:

$allowed_ext = array(".coa");

Description of the soft: list_dir_files.php

Major credits: phpDIRList 2.0 -©2005 Ulrich S. Kapp :: Systemberatung ::

$do_link = TRUE;
$sort_what = 0; //0- by name; 1 - by size; 2 - by date
$sort_how = 0; //0 - ASCENDING; 1 - DESCENDING

#

function dir_list($dir){
$i=0;
$dl = array();
if ($hd = opendir($dir)) {
while ($sz = readdir($hd)) {
if (preg_match("/^./",$sz)==0) $dl[] = $sz;$i.=1;
}
closedir($hd);
}
asort($dl);
return $dl;
}
if ($sort_how == 0) {
function compare0($x, $y) {
if ( $x[0] == $y[0] ) return 0;
else if ( $x[0] < $y[0] ) return -1;
else return 1;
}
function compare1($x, $y) {
if ( $x[1] == $y[1] ) return 0;
else if ( $x[1] < $y[1] ) return -1;
else return 1;
}
function compare2($x, $y) {
if ( $x[2] == $y[2] ) return 0;
else if ( $x[2] < $y[2] ) return -1;
else return 1;
}
}else{
function compare0($x, $y) {
if ( $x[0] == $y[0] ) return 0;
else if ( $x[0] < $y[0] ) return 1;
else return -1;
}
function compare1($x, $y) {
if ( $x[1] == $y[1] ) return 0;
else if ( $x[1] < $y[1] ) return 1;
else return -1;
}
function compare2($x, $y) {
if ( $x[2] == $y[2] ) return 0;
else if ( $x[2] < $y[2] ) return 1;
else return -1;
}

}

##################################################

We get the information here

##################################################

$i = 0;
while($file=$directory->read()) {
$file = strtolower($file);
$ext = strrchr($file, ‘.’);
if (isset($allowed_ext) && (!in_array($ext,$allowed_ext)))
{
// dump
}
else {
$temp_info = stat($file);
$new_array[$i][0] = $file;
$new_array[$i][1] = $temp_info[7];
$new_array[$i][2] = $temp_info[9];
$new_array[$i][3] = date(“F d, Y”, $new_array[$i][2]);
$i = $i + 1;
}
}
$directory->close();

##################################################

We sort the information here

#################################################

switch ($sort_what) {
case 0:
usort($new_array, “compare0”);
break;
case 1:
usort($new_array, “compare1”);
break;
case 2:
usort($new_array, “compare2”);
break;
}

###############################################################

We display the infomation here

###############################################################

$i2 = count($new_array);
$i = 0;
echo "






";
for ($i=0;$i<$i2;$i++) {
if (!$do_link) {
$line = “”;
}else{
$line = ‘”;
}
echo $line;
}
echo “
File name File Size Last Modified
” .
$new_array[$i][0] .
” .
number_format(($new_array[$i][1]/1024)) .
“k”;
$line = $line . “
” . $new_array[$i][3] . “
’ .
$new_array[$i][0] .
”;
$line = $line . number_format(($new_array[$i][1]/1024)) .
“k” . “
” .
$new_array[$i][3] . “
”;

?>[/code]

[code]<?PHP
function getFileList($dir)
{
// array to hold return value
$retval = array();

// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "./NCFA/exports/";

// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
  // skip hidden files
  if($entry[0] == ".") continue;
  if(is_dir("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry/",
      "type" => filetype("$dir$entry"),
      "size" => 0,
      "lastmod" => filemtime("$dir$entry")
    );
  } elseif(is_readable("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry",
      "type" => mime_content_type("$dir$entry"),
      "size" => filesize("$dir$entry"),
      "lastmod" => filemtime("$dir$entry")
    );
  }
}
$d->close();

return $retval;

}

// output file list in HTML TABLE format
echo “<table border=“1”>\n”;
echo “\n”;
echo “ Name Type Size Last Modified \n”;
echo “\n”;
echo “

\n”;
foreach($dirlist as $file) {
echo “\n”;
echo “{$file[‘name’]}\n”;
echo “{$file[‘type’]}\n”;
echo “{$file[‘size’]}\n”;
echo “”,date(‘r’, $file[‘lastmod’]),"\n";
echo “\n”;
}
echo “\n”;
echo “\n\n”;
?>[/code]

The top one results in the top error and the bottom one results in the bottom error on my website:
http://cfa-football.com/NCFA.php

Well, you did not show us the lines in error…

Which lines are 641 and 744??? Perhaps we can help you figure it out. (On the live page, it only shows your
HTML and JS code of course, so we really need to look at lines 635-645 and 735-750 or less maybe…

Also, files? Why are you not using a database for this type of project?

The website is created in WYSIWYG Web Builder 10… I’m not an html expert LOL…

How’s this?

Code starts at 548 and ends at 757… I’ve noted 641 and 744.

[code]


NCFA League Files
File:
<?PHP # The current directory $directory = dir("./NCFA/exports/");

If you want to turn on Extension Filter, then uncomment this:

$allowed_ext = array(".coa");

Description of the soft: list_dir_files.php

Major credits: phpDIRList 2.0 -©2005 Ulrich S. Kapp :: Systemberatung ::

$do_link = TRUE;
$sort_what = 0; //0- by name; 1 - by size; 2 - by date
$sort_how = 0; //0 - ASCENDING; 1 - DESCENDING

#

function dir_list($dir){
$i=0;
$dl = array();
if ($hd = opendir($dir)) {
while ($sz = readdir($hd)) {
if (preg_match("/^./",$sz)==0) $dl[] = $sz;$i.=1;
}
closedir($hd);
}
asort($dl);
return $dl;
}
if ($sort_how == 0) {
function compare0($x, $y) {
if ( $x[0] == $y[0] ) return 0;
else if ( $x[0] < $y[0] ) return -1;
else return 1;
}
function compare1($x, $y) {
if ( $x[1] == $y[1] ) return 0;
else if ( $x[1] < $y[1] ) return -1;
else return 1;
}
function compare2($x, $y) {
if ( $x[2] == $y[2] ) return 0;
else if ( $x[2] < $y[2] ) return -1;
else return 1;
}
}else{
function compare0($x, $y) {
if ( $x[0] == $y[0] ) return 0;
else if ( $x[0] < $y[0] ) return 1;
else return -1;
}
function compare1($x, $y) {
if ( $x[1] == $y[1] ) return 0;
else if ( $x[1] < $y[1] ) return 1;
else return -1;
}
function compare2($x, $y) {
if ( $x[2] == $y[2] ) return 0;
else if ( $x[2] < $y[2] ) return 1;
else return -1;
}

}

##################################################

We get the information here

##################################################

$i = 0;
while($file=$directory->read()) {
$file = strtolower($file);
$ext = strrchr($file, ‘.’);
if (isset($allowed_ext) && (!in_array($ext,$allowed_ext)))
{
// dump
}
else {
$temp_info = stat($file); 641**
$new_array[$i][0] = $file;
$new_array[$i][1] = $temp_info[7];
$new_array[$i][2] = $temp_info[9];
$new_array[$i][3] = date(“F d, Y”, $new_array[$i][2]);
$i = $i + 1;
}
}
$directory->close();

##################################################

We sort the information here

#################################################

switch ($sort_what) {
case 0:
usort($new_array, “compare0”);
break;
case 1:
usort($new_array, “compare1”);
break;
case 2:
usort($new_array, “compare2”);
break;
}

###############################################################

We display the infomation here

###############################################################

$i2 = count($new_array);
$i = 0;
echo "






";
for ($i=0;$i<$i2;$i++) {
if (!$do_link) {
$line = “”;
}else{
$line = ‘”;
}
echo $line;
}
echo “
File name File Size Last Modified
” .
$new_array[$i][0] .
” .
number_format(($new_array[$i][1]/1024)) .
“k”;
$line = $line . “
” . $new_array[$i][3] . “
’ .
$new_array[$i][0] .
”;
$line = $line . number_format(($new_array[$i][1]/1024)) .
“k” . “
” .
$new_array[$i][3] . “
”;

?>

<?PHP function getFileList($dir) { // array to hold return value $retval = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "./NCFA/exports/";

// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
  // skip hidden files
  if($entry[0] == ".") continue;
  if(is_dir("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry/",
      "type" => filetype("$dir$entry"),
      "size" => 0,
      "lastmod" => filemtime("$dir$entry")
    );
  } elseif(is_readable("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry",
      "type" => mime_content_type("$dir$entry"),
      "size" => filesize("$dir$entry"),
      "lastmod" => filemtime("$dir$entry")
    );
  }
}
$d->close();

return $retval;

}

// output file list in HTML TABLE format
echo “<table border=“1”>\n”;
echo “\n”;
echo “ Name Type Size Last Modified \n”;
echo “\n”;
echo “

\n”;
foreach($dirlist as $file) { 744
echo “\n”;
echo “{$file[‘name’]}\n”;
echo “{$file[‘type’]}\n”;
echo “{$file[‘size’]}\n”;
echo “”,date(‘r’, $file[‘lastmod’]),"\n";
echo “\n”;
}
echo “\n”;
echo “\n\n”;
?>
[/code]

Thanks, Rob, that helps a lot !

So, the second error jumped right out at me with this version of your code.
In line 744, you start a loop. Inside that loop, you have a bad function in and echo line. I am guessing that
this bad function call is the problem. So, for that part, I will guess in line #749, you have:
[PHP]
echo “

”,date(‘r’, $file[‘lastmod’]),"\n";
[/PHP]
I think this should be periods, not comma’s which turn it into a function looking for arguments…
[PHP]
echo “” . date(‘r’, $file[‘lastmod’]) . “\n”;
[/php]
That one is a common error and was easy to see once I knew the line it was on…

Well, half of it is solved… Looking at the other now…

Well, I have not tested it on my server, but, the file code appears to be correct. I did notice extra ()'s on one
line that is odd and might cause the problem. So, that is line #363:
if (isset($allowed_ext) && (!in_array($ext,$allowed_ext)))

I think the (! might be causing it to not go thru the look correctly and that would mess up call the STAT()
function. Try it this way and let us know…
[php]
if (isset($allowed_ext) && !in_array($ext,$allowed_ext))
[/php]

Unfortunately after making both changes nothing has changed… it still doesn’t work.

Rob, I am looking over it further… I found a lot of errors in the code, but, not sure how to fix them.
If you go to the page and view the source of it, just before it creates the side-bar list of files, it throws out
the errors. Then, it goes on to show the table. So, it is a two-fold problem. I will figure it out…

But, in the meantime, just above that in the view-source, the data is displayed AFTER the HTML BODY has
been closed. That is an issue that is more important to fix. Looking into that one now.

Check back in a few minutes…

Rob, I assume you were posting partial page of info. That is okay. But, I can’t find a few things to figure this
all out. First, this code makes no sense…
$d = @dir($dir) or die(“getFileList: Failed opening directory $dir for reading”);
while(false !== ($entry = $d->read())) {
The error code is suppressed using the “@”. Not sure why they added that. The WHILE is odd because it
tests for ($entry =$d->read()) being false, so it is basically doing a compare that is not needed. As far as I
can see anyways. Should be:
$d = dir($dir) or die(“getFileList: Failed opening directory $dir for reading”);
while($entry = $d->read()) {
(This version does not suppress error messages and it does a normal WHILE which is what the word WHILE
means! …while… not while(empty != full)???..

Now, the error at line#744 where the line is:
foreach($dirlist as $file) { // 744
(I added commenting…) This line is based on the variable $dirlist… I could not find in the code where it
creates this variable. I was going to guess that this is the problem. We would need to find out what is in
that variable, $dirlist. The comma’s versus periods still need to be correct, but, that is not causing the real
error. Can you either send me the entire file in a private-message or at least post the section where the
code create the $dirlist variable? If you want to try to debug it yourself, just before line #744 place the
lines:
print_r($dirlist); echo “
”;
and then it will dump what is inside the variable. The error message that is being throw says that the
content of that variable is the issue. Also, in that code, it is using “/n” for the tables. It is not needed.

Doubt this helps much, but, gives you some ideas to start with. This code was done by more than one
person from the formatting of it all. The site is nice. I like the background honeycomb, layout, colors, titles.

Thanks for the nice comments on the site ;D

I tried the other things you suggested and its still not working :frowning:

I’m at a loss… maybe you (or someone else) can help me create a php script to display the files in a specific directory on my website. I need to show the file date and file name that are uploaded to the directory /NCFA/exports/

I can do that… Give me a few minutes…

Rob, do you know which version of PHP you are using?

5.4.19 according to my forum.

Well, there are many ways to do this. I came up with one that was very small, but, it needs at least PHP 5.3.
I figured I would take the time to create a more universal routine for you. Here is one. I did not test it as
yet, but, it should work.
[php]
$dir_path="/NCFA/exports/";
$dir = opendir($dir_path);
$file_list = array();
while($file = readdir($dir)){
if ($file != “.” and $file != “…”) { // Skip empty entries…
$file_list[filectime($dir_path . $file) . " : " . $file;
}
}
closedir($dir);
krsort($file_list);
foreach($file_list as $filename) {
echo $filename . “
”;
}
[/php]
It grabs the files and their creation time and store them in an array using the creation time as the index.
The creation time is both the time and filename so that there are never any dups for the indexes.
Then, it does a sort on the creation times giving you a sorted list. Then, it prints out the list. You could
change the way it sorts to be desc or ascending as needed or on most recently modified. Basically any
way you might want… You can reformat the way the timestamp displays if needed…

Try it and let us know if it does what you want it too…

I tried this one and got an error

Parse error: syntax error, unexpected ';', expecting ']' in /home/content/29/8946729/html/NCFA.php on line 569

So, Rob, my flying fingers made a mistake… Try this version… I was missing a bracket!

[php]
$dir_path="/NCFA/exports/";
$dir = opendir($dir_path);
$file_list = array();
while($file = readdir($dir)){
if ($file != “.” and $file != “…”) { // Skip empty entries…
$file_list[filectime($dir_path . $file)] . " : " . $file;
}
}
closedir($dir);
krsort($file_list);
foreach($file_list as $filename) {
echo $filename . “
”;
}
[/php]
Let us know if that works…

This is what I’m getting now…

Warning: opendir(/NCFA/exports/): failed to open dir: No such file or directory in /home/content/29/8946729/html/NCFA.php on line 578

Warning: readdir() expects parameter 1 to be resource, boolean given in /home/content/29/8946729/html/NCFA.php on line 580

Warning: closedir() expects parameter 1 to be resource, boolean given in /home/content/29/8946729/html/NCFA.php on line 585

So I changed the directory to ‘./NCFA/exports/’ and that got rid of the error but nothing shows up.

If the folder is in the ROOT of the site, then it is /NCFA/ …
If the folder is under the current folder where the PHP file code is, then it is NCFA/ (no starting slash!)
If the folder is under a folder one level below the PHP folder, then it is …/NCFA/…
If the folder is under a folder two levels below the PHP folder, then it is …/…/NCFA/…

Since, we have no idea where they folder is these might help you steer it correctly…

Hope that make sense, if not, we will need to know the folder layouts…

ROOT/NCFA/exports is the order it goes.

I was looking at your website. It seems to be getting there, no errors…

I did notice that there is a small issue with the numbers in the list. It lists single digit numbers as higher ones.
Like team 6 is placed where team 60 should be. To fix that, you would need to format it somehow…

But, looks like you are getting there!

Sponsor our Newsletter | Privacy Policy | Terms of Service