Jump to content

[SOLVED] include() not including


proggR

Recommended Posts

I'm trying to include some posts into a page. The filenames are saved in multiple textfiles based on keyword. The values are all read from the text files fine and as you'll see in the lower portion of code I include a link to the files themself, all of which display fine when I click on them. The include() function isn't displaying the files. They're all php files and like I said they can be displayed when I go to them directly. I've changed the parameter in include so that I just typed in the filename used by $value and that includes fine.  Using the variable it doesn't seem to though. I've also tried putting the parameter in quotes or including the 127.0.0.1 in the path but that doesn't help.If anyone has any ideas why this may not be displaying it would be greatly appreciated. Aside from some added features to organize my code better this is the last thing I need to get it up and running the way I've planned.

 

The code that reads in the values from the URL and assigns the variables accordingly:

<?php
if ($_GET["keyword"] == false){
$keyword = "all";
}
else{
$keyword=$_GET["keyword"];
}

$course = $keyword.".txt";//sets the value of $course to the appropriate text file based on the keyword

//assigns each post to a one dimensional array which will be split into a 2d array later
$fh = fopen($course,'rt');
if($fh==false)
die("There hasn't been anything created for that course.");

while (!feof($fh)) {
        $item[$counter]=fgets($fh);
$counter = $counter+1;	
    }

fclose($fh);
//end the reading of the file


if ($_GET["page"] == false){
$page = 0;
}
else{
$page=$_GET["page"];
}

$post= array_chunk($item,5);// splits the posts into pages with 5 posts per page
?>

 

The code that displays the links within the template and that should include the formatted php files the links attach to:

<?php
//prints all the posts on page

foreach ($post[$page] as $value) 
{ 

include($value);
echo "<a href =\"".$value."\">".$value."</a><br>";
}

?>

 

I'm sure there's something small I'm overlooking but I've tried changing everything I could think of. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/113815-solved-include-not-including/
Share on other sites

Thank you. I couldn't remember those but have seen them before.

I get:

Warning: include( Today_Ja101_TestWithOO15.php ) [function.include]: failed to open stream: Invalid argument in E:\Program Files\Apache Group\Apache2\htdocs\testing.php on line 100

 

Warning: include() [function.include]: Failed opening ' Today_Ja101_TestWithOO15.php ' for inclusion (include_path='.;C:\php5\pear') in E:\Program Files\Apache Group\Apache2\htdocs\testing.php on line 100

 

each time it tries to include the file. What you don't see here is that in the "Failed opening" section there is actually a huge gap between the end of the filename and the closing quotation. Also could anyone tell me what the '.;C:\php5\pear' is referencing? because the partition I'm running all this from is actually my E: and that is where both Apache and PHP are running from so I don't know why its giving me that path. Line 100 refers to "include($value);". And at the top of the page I get the errors:

 

Notice: Undefined index: keyword in E:\Program Files\Apache Group\Apache2\htdocs\testing.php on line 19: which is: if ($_GET["keyword"] == false)

 

Notice: Undefined index: page in E:\Program Files\Apache Group\Apache2\htdocs\testing.php on line 43: which is: if ($_GET["page"] == false)

 

Both of these refer to the values passed through get but I'm checking them to see if they're present and if not I have default values for them (which are present in the else section). I had planned to rewrite them but forget how I'd planned to do that. Is there anyway to avoid an error if I don't have a value passed?

And I'm still not getting anything included. Do these errors help anyone? I'll try looking them up elsewhere as well.

 

 

If the filename is correct but there is extra white-space surrounding it (which would mean that the white-space is present in the $page[] array), then it would be best to find the cause of the extra white-space and eliminate it. If the white-space is supposed to be there, then use the trim() function to remove it from the $value variable.

 

C:\php5\pear' is part of the include_path= setting. When php could not find the include filename in the CWD (current working directory), it searched the include_path.

 

The two undefined index messages are because if ($_GET["keyword"] == false) accesses the contents of the $_GET variable. The way to avoid the message is to use the isset() function, which checks if the variable is set without actually accessing it.

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.