?
Solved

PHP Include

Posted on 2007-03-30
5
Medium Priority
?
223 Views
Last Modified: 2008-01-09
I want to dynamically generate an include_path string to pass to a PHP include function. The code I have below generates an error (below):

if($row['extrainfo'] != null || $row['extrainfo'] != ""){
$include_path = "DVDPages\\".$row['extrainfo'];
echo "<tr><td colspan=2>"; include($include_path); echo "</td></tr>";
}

Warning: include(DVDPages\antbullyextra.htm) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\E-Commerce\dvd.php on line 109

Warning: include() [function.include]: Failed opening 'DVDPages\antbullyextra.htm' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\E-Commerce\dvd.php on line 109

However, If I hardcode the include path into the include function (as below) it works. The string values are exactly the same.  $row['extrainfo'] = 'ews.htm'

if($row['extrainfo'] != null || $row['extrainfo'] != ""){
$include_path = "DVDPages\\".$row['extrainfo'];
echo "<tr><td colspan=2>"; include("DVDPages\ews.htm"); echo "</td></tr>";
}

Can Anyone help?

Many Thanks
0
Comment
Question by:inghfs
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:mukhtar2t
ID: 18826798
Have you this file 'DVDPages\antbullyextra.htm'  on your working directory
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 2000 total points
ID: 18826825
function getRootPath() {
      $tmp = stripslashes($_SERVER['DOCUMENT_ROOT']);
      $regExPattern = "/^[a-zA-Z0-9\\\:]+$/";
      preg_match($regExPattern, $tmp, $arr);
      if (!empty($arr)) {
            return $arr[0];
      }else{
            return "";
      }      
}

$inc_virtual = getRootPath() . "\\DVDPages\\";


include $inc_virtual. $row['extrainfo'];
0
 

Author Comment

by:inghfs
ID: 18826957
include $inc_virtual. $row['extrainfo']; Did not work, the same error occurs:

Warning: include(DVDPages\antbullyextra.htm) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\E-Commerce\dvd.php on line 122

Warning: include() [function.include]: Failed opening 'DVDPages\antbullyextra.htm' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\E-Commerce\dvd.php on line 122

DVDPages is a directory containing antbullyextra.htm. in my working directory
0
 

Author Comment

by:inghfs
ID: 18826970
Sorry, my mistake. include $inc_virtual. $row['extrainfo']; does work.

Many Thanks
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18826982
You're welcome
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question