Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Include

Posted on 2007-03-30
5
Medium Priority
?
220 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

618 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