Jump to content

Counting Files and dynamic content HELP


sakr

Recommended Posts

I found a piece of code from your site to count the number of files in a directory and combined that with my own while loop, and I'm hoping someone can tell me why I get the error:

Warning: opendir(/articles/): failed to open dir: No such file or directory in /home/content/d/o/s/dossilfuels/html/index.php on line 20

The code is:
[code]               <?php
                    if ($handle = opendir('/articles/')) {
                        $cnt=0;
                        while (false !== ($file = readdir($handle))) {
                            if ($file != "." && $file != "..") {
                                $cnt++;
                            }
                        }
                    }
                    
                    $counttop = $cnt;
                    $countbot = $cnt - 6;
                    
                    while ($counttop > $countbot){
                        include("articles/article".$counttop."php");
                        $counttop--;
                    }
                ?>[/code]


I also tried removing the "/" at the end of "/articles", but the same message came up.

Thanks you very much for any help I get!
(p.s. the site is [a href=\"http://dossilfuels.com\" target=\"_blank\"]http://dossilfuels.com[/a])
Link to comment
Share on other sites

It's telling you that "/articles/" does not exist.

Where in your file structure is the articles folder? If it is subdirectory of the folder you are running the script in, change it to "./articles/", or just "articles".

Familiarize yourself with relative paths...that will help greatly...

"./" means the current directory.
"../" means the parent directory.
"../../" means two directories above.
And so on.

Using "/articles/" is telling php that the folder is a subdirectory of the document root, if it is and the folder exists, check permissions on the folder.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.