Include Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Include Problem

Post by Zeceer »

<?php

$dirname = "produkter";
$dh = opendir( $dirname );

while( $file = readdir( $dh ) )
{
include("$file");
}

?>

Why want his work?

This is what I see when running this code:

Warning: Failed opening '.' for inclusion (include_path='.;c:\php4\pear') in D:\inc shop\index.php on line 29

Warning: Failed opening '..' for inclusion (include_path='.;c:\php4\pear') in D:\inc shop\index.php on line 29

Warning: Failed opening 'produkt1.php' for inclusion (include_path='.;c:\php4\pear') in D:\inc shop\index.php on line 29

Warning: Failed opening 'produkt2.php' for inclusion (include_path='.;c:\php4\pear') in D:\inc shop\index.php on line 29

Warning: Failed opening 'produkt3.php' for inclusion (include_path='.;c:\php4\pear') in D:\inc shop\index.php on line 29

I've tried what I know, but nothing seams to work. Please help :oops:
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

which line is line 29?
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

include("$file");

This is line 29 :D
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

try

Code: Select all

if(is_file("$dirname/$file"))
    include "$dirname/$file";
this time. In the future, read the error messages carefully. PHP is trying to open d:\inc shot\., d:\, and d:\inc shop\produktX.php. If the file you're trying to include isn't in the current execution directory (signified by the '.' in the include_path, by the way), then PHP won't be able to find it unless you direct it to the file.
Post Reply