Solved

PHP Include

Posted on 2007-03-30
5
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to dynamically set the form action using jQuery.

691 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