Solved

PHP Include

Posted on 2007-03-30
5
214 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to dynamically set the form action using jQuery.

828 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