Solved

PHP Include

Posted on 2007-03-30
5
210 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
Comment Utility
Have you this file 'DVDPages\antbullyextra.htm'  on your working directory
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, my mistake. include $inc_virtual. $row['extrainfo']; does work.

Many Thanks
0
 
LVL 29

Expert Comment

by:rdivilbiss
Comment Utility
You're welcome
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now