Help?!

When I put it correctly (based on what you posted which is /NCFA/exports/ with no . ) this is the error:

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, here is how you set it correctly…

Let’s say this is your site:
http://cfa-football.com/

So, the ROOT is that… http://cfa-football.com/

If you store your code under ROOT/HTML/ as you showed in the last post, your page is something like:
http://cfa-football.com/html/NCFA.php But, this depends on what you are using for a server and how it is
set up for the defaults to the site. Sometimes that your domain and PUBLIC_HTML or whatever. SO, it is
normally set up as most sites are laid out loosely like this…

ROOT
—Libraries
------Javascript
------Includes
—Images
—Data
------PDFs
—Uploads
—ETC

Basically any website has special folders that are used for various reasons. You have to know your layout
of your site. If your PHP code page is stored at level 2 (in a folder that is inside of the ROOT), then, any
pointers to a level 2 folder (another folder in the ROOT) would need to use “…/” to point it back one level
to level 1 (ROOT) then to the needed folder. If the code page is in a level 2 folder and needs to access a
level 3 folder not inside the current folder, it would need something like this:
“…/” get back to level 1 or ROOT…
“…/Libraries” Go to the level 2 folder
“…/Libraries/Includes/” Go to the level 3 folder

Your code in any folder can access any other folder, but, has to be pointed in the correct order.

Hope that makes sense…

My post got cut off, here is the rest…

So, if your code is inside a folder that is in the ROOT, and you need to access a second folder that is also
in the ROOT, you have to go back one level to the ROOT and then to the second folder. SO if your layout is
like this:

ROOT
----Libraries
—Javascript
—Includes
----HTML
—football_code
—somefolder
----Images
----Uploads

And, your page is inside of HTML and under the football_code folder, you would have to back up two levels
to get to the images on the site like this: " …/…/Images/somepix.jpg " when you want to load an image.
It all depends on where the files are stored how you move around the site.

Hope that helps explain it…

Okay well NCFA is a library in the root directory and exports is inside that folder. So it should be /NCFA/exports/ but I’m getting those errors above…

Well, yes and no…

So, depends on where the page is located.

If it is in the root, it should be NCFA/exports/
(this means that the program and the NCFA folder are in the same folder)

If it is in a folder in the root, it should be …/NCFA/exports/
(this means that the program is in the same level of the root as the NCFA folder and you need to back
up to the root then go into the NCFA folder)

Leaving for the night, so hope you understand this!

Its not a rush (since you’re heading out anyways) but when I put it correctly [or what I’m assuming is correct] the errors go ahead but nothing shows up. The text that is there is something that I typed in myself. The file names/data should be showing up below the ID Key I typed.

What am I doing wrong here?

This is the code:

<?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 . "<br>"; } ?>

First, lets modify you code to this,

[php] <?PHP
try {
$dir_path="./NCFA/exports/";

    if ( !is_dir( $dir_path ) { // checks if path is valid
        exit("Path: $dir_path not valid.");
    }

      $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 . "<br>";
   }

} catch ( Exception $e ) {
echo $e->getMessage();
}
?>[/php]

That gives us errors, if there are any and runs some checks.

A few comments:

[php] if ($file != “.” and $file != “…”) { // Skip empty entries…[/php]

. and … are not empty entries. They are valid directories. It is semantics, but something to understand.
Next, do a print_r on $file_list and see what you get. I don’t think it is holding what you think it is.

Rob, . / and . . / is two different things ! ! ! !

You can’t use ./ That will not work… I told you it must be …/NCFA/exports/ …

./ means something else… Actually, it means the current directory. / means ROOT ./ means current dir
Therefore, ./some_folder is exactly the same as some_folder…
So, ./NCFA means the same as NCFA which would only work if NCFA was inside the page’s folder.
(That is not where you told me it was…)

You need to use …/ to back up one level…

Just got home… Did you read my notes? They all said for the entire thread TWO PERIODS! Heee!

Try using …/ to back up one level not ./ I realize it is a very minor difference, but…

…/NCFA/exports/ = directory does not exist:

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

Here’s the directory in my FTP:

I want the php script to tell me the name of the files and the date they were uploaded…

They are located in (correct me if I’m wrong) ROOT/NCFA/exports which is? ./NCFA/exports/, NCFA/exports, or what?

When I try ./NCFA/exports/ and NCFA/exports (which are the same thing you said?) nothing shows up. Where the script is placed in my PHP page its blank.

Well, I think you are very close. Yes, ./NFCA/ is exactly the same as NFCA/

Now where is your code? Is it inside NFCA ??? Since NFCA is inside the ROOT of your site, where is your
page that uses this code???

Also, the warning says you didn’t use quotes! opendir(…/NCFA/exports/) opendir("…/NCFA/exports/")

The code is not inside NCFA. It is in NCFA.php which is inside of the root folder.

Also, I was sure to use “…/NCFA/exports/” and I get the same error.

FINALLY ! Yes! I asked a few times where your code was…

Well, if the PHP script is inside the ROOT folder, then you need nothing. It should be just
opendir(“NCFA/exports/”) Nothing more…

Hope that works! If not post the current version of the routine and I will upload it to my server and test it.

Well, I just looked at the opendir() function specs on w3Schools and they say it should include an opening
slash. (At least they use it in their sample code.)

SO, if that is true, then use opendir("/NCFA/exports/")

:frowning:

Using /NCFA/exports/ didn’t work…

[code]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[/code]

Removed the slash all together brings me back to a blank section where the code should be.

Well, post the code of the current version of the routine. I will copy it to my server and change the dir so
I can test it…

What is the root directory for FTP? I’ll post a pic of a centos structure when I get a chance.

How much of the code do you need?

Just the dir code we are working on…

<?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 . "<br>"; } ?>

Great! I got the same error… Be back in a couple minutes! Some issue with the opendir() function!

Sponsor our Newsletter | Privacy Policy | Terms of Service