PHP - Php Include Path Error
Dear Sir,
I am building a small framework and going to check on my local computer by using "XAMPP Server" so i have 2 folder and 5 file the hierarchy is:
- inc
- config.php (Contains all configuration of website like, Directory Separator, Include Path .. etc.)
- autoload.php
-classes
- Url.php (Class)
- Core.php (Class)
- index.php
when i try to run this application i got following Error:
Warning: require_once(Core.php): failed to open stream: No such file or directory in C:\xampp\htdocs\completed\inc\autoload.php on line 7
Fatal error: require_once(): Failed opening required 'Core.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\completed\inc\autoload.php on line 7 I have also tried to change settings of include_path php.ini changes are following: 1. remove ',;' from include_path 2. try to change to this '\php\PEAR' 3. put ';' in starting og php_include_path my current default setting of php include is: ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; Similar TutorialsHello Everyone, i am fairly new in PHP coding, and facing some issue with include function in php. my problem is as follows: in a php script which is located at "/include/cart.php" i am including a html page "cart_add.html" which is at location "/cart_add.html" now whenever i am clicking on any links on this page "cart_add.html" browser looking for all other pages at location "/include/" instead of "/" so in the browser i see url as "http://localhost/include/index.html" instead of "http://localhost/index.html" so i get error like this : [an error occurred while processing this directive] The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please help me to resolve this issue. Thanks very much In the file "secure/checkout.php" I have... Code: [Select] <?php require_once "../config.inc.php"; ?> which is Relative. Can I use an Absolute Path instead?? Debbie Hi all, i was trying to include a php file in an index file into another files and those included file is including one file also. But for some reason the database connection file is not included. this is the map structure www/index.php <---- the file that uses include www/newsletter/newsletter.php <---- has a form with action process.php www/newsletter/process.php <--- this has an include referring to database.php www/newsletter/database.php <--- the databasefile This is what i did but it gives a server error in index.php include('newsletter/newsletter.php'); innewsletter.php <form action="newsletter/process.php" method="post"><!--- some form stuff--></form> in process.php include('database.php'); I really don't understand why it doesn't work and it's giving a server error 500. The form loads like it should in the index.php but the rest doesn't any help is appreciated. Hi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? Hi, I am creating an image with a random number to use as a capcha. I've done the image creation before and had it working but now I have a font path error. However......I know my font path is the same...I didn't change it and it was working perfectly. What I changed was I made the image creation piece of code into a function...so I could return a value and use the function as a capcha....can you not use this image creation stuff in a function? The difficulty is getting hold of the random number to verify someone typed it correctly. If you have any ideas I'm open to other methods. My code is: function capcha(){ $capchatxt = rand(10000,99999); $font = '/includes/balloon.ttf'; $textarray = imagettfbbox(30, 0, $font, $capchatxt); $width = $textarray[2]-$textarray[0]; $height = $textarray[3]-$textarray[7]; $image = imagecreate($width+10,$height+10); $background = imagecolorallocate ($image, 255,227,232); $colour = imagecolorallocate($image, 0, 154, 239); // blue; $pink = imagecolorallocate($image, 239, 0, 144); // crimson pink; $peach = imagecolorallocate($image, 255, 227, 232); // pale pink; // Add the text imagettftext($image, 30, 0, 5, $height+5, $pink, $font, $capchatxt); header('Content-type: image/png'); imagepng($image); imagedestroy($image); return $capchatxt; } At the moment: The function and the font file are in the same folder. The file which is calling the function is in a different folder. BTW - Forgot to mention that right now I'm using localhost (xampp)...not a real server. Thanks for the help. IceKat Hi sorry for the trouble guys but i'm really stuck on this one, and i've tried everything i can. (I've been using php only for sometime now) I'm stuck at this code and can't figure out why this is failing. Objective of the script : To try and include BOTH files or throw and exception if even one fails. I tried : Including just one at a time. Its fine, so i know the path is correct. I tried a if (! (expr1 && expr2) ) statement to check if the syntax is correct to create a everything or nothing logic. $offlineLibraryPath = '/var/www/common/lib'; // Attempt to include the files try { if(! ( require_once($offlineLibraryPath.'/variables/all.php') && require_once($offlineLibraryPath.'/functions/all.php') ) ) { throw new Exception ('Including all the common library files failed.'); } } catch (Exception $e) { echo '<b>Error</b> :'.$e->getMessage(); } I get this error : Warning: require_once(1): failed to open stream: No such file or directory in /var/www/common/lib/startupIncludes.php on line 18 Fatal error: require_once(): Failed opening required '1' (include_path='/var/www/common/lib/: /var/www/culturesque/lib/: /var/www/mine/lib/') in /var/www/common/lib/startupIncludes.php on line 18 Thanks in advance for the help! I have the code: <?php if ($_GET['id'] == "24") { $page = "/24/"; } elseif ($_GET['id'] == "35") { $page = "/35/html/index.html"; } elseif ($_GET['id'] == "36") { $page = "/36/html/index.html"; } elseif ($_GET['id'] == "46") { $page == "/46/index.html"; } elseif ($_GET['id'] == "263") { $page = "/263/index.html"; } else { $page = "welcome.php"; } ?> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Page Preview - Nathan Watson</title> <link rel="stylesheet" type="text/css" href="/style.css" /> </head> <?php include("x.php"); include($page); ?> but when I use an id it gives me the error Code: [Select] Warning: include(/263/index.html) [function.include]: failed to open stream: No such file or directory in /home/content/n/a/t/nathanwatson/html/projects/index.php on line 23 Warning: include() [function.include]: Failed opening '/263/index.html' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/n/a/t/nathanwatson/html/projects/index.php on line 23 And I have absolutely no idea why Hi, I am trying to upload my PHP file in a directory on the sub domain called "pro" the error I am getting is I have used <?php include ("/pro/error_function.php"); ?> Warning: include(/pro/error_function.php) [function.include]: failed to open stream: No such file or directory in and Warning: include() [function.include]: Failed opening '/pro/error_function.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') could some one help me what is the problem? Hello Everyone, I am very very new to php, i recetly code some php script for my website, but now stuck with some horrible errors. At first the same scripts were running quite fine, but just today its start giving me erroe, i can't figure out whats the issue, i try to uninstall and install XAMPP again and again, configure php.ini file but still no result. following are the error message i am getting: Warning: include_once(C:/xampp/htdocs\include\search.php?start=0&page=0&product=black&cat=All Categories) [function.include-once]: failed to open stream: No error in C:\xampp\htdocs\initialsearch.php on line 6 Warning: include_once() [function.include]: Failed opening 'C:/xampp/htdocs\include\search.php?start=0&page=0&product=black&cat=All Categories' for inclusion (include_path='.;\xampp\php\PEAR') in C:\xampp\htdocs\initialsearch.php on line 6 i also set the include path in php.ini , but its also not helped. It will be a great help if someone can help me to solve this issue. i am attaching following files alone : initialsearch.php search.php Also , i am running WINDOWS 7 and XAMPP 1.7.3 Waiting for some help thanks again. Hello. I am having some trouble with an include line. At the very top of my .php page I have the following Code: [Select] <?php include ('/IUS/Login/form_process.php'); ?> When I open the page using - localhost/IUS the rest of the page seems to load fine but at the very top I have this error message Quote Warning: include(/IUS/Login/form_process.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\IUS\Index.php on line 1 Warning: include() [function.include]: Failed opening '/IUS/Login/form_process.php' for inclusion (include_path='.;C:\php5\pear') in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\IUS\Index.php on line 1 My file structure is as follows Inside my apache2.2 there is the htdocs folder inside that there is a folder called IUS IUS has the index.php file in it as well as a css style sheet and two folders. 1. folder called 'images' 2.folder called Login Login has the file 'form_process.php' so the structure looks something like this - Apache2.2 htfocs IUS - Index.php, style.css Images - BackgroundRep.png etc... Login - form_process.php, Config.php (red = folder) Where am I going wrong? I can tell that its unable to find the form_process.php file in the path that I am specifying but I am unsure why? Thank you in advance for any help. Hi, i have a problem to include files witch have multiple dots, here is example :
include("/path/to/filename.txt"); // This one work fine
include("/path/to/filename.txt.txt"); // Give 500 error, even if the full path is correct
include("/path/to/dire.c.tory/filename.txt"); // Give 500 error, even if the full path is correct
So what is the problem ?
How to know if a giving path $path contain files or directories with multiple dots or just one or no dot ? something like :
function is_multiple_dots($path) { // return true in the case of presence of two or more dots in the name of at least one directory or filename // return false in the case of presence of at maximum of one dot per filename or directory name }Regards Edited by Dareros, 08 October 2014 - 08:07 PM. Hi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated. CanI put one INCLUDE statement INSIDE of another INCLUDE statement? Hi Guys.. Merry Christmas Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with. Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes content in a content div from external .php pages, my structure kinda goes like this.. (simplified) site/ index.php content/ fronpage.php products.php contact.php The HTML looks like this. <div id="menu"> <ul> <li><a href="index.php?page=frontpage">frontpage</a></li> <li><a href="index.php?page=products">frontpage</a></li> <li><a href="index.php?page=contact">frontpage</a></li> </ul> </div <div id="main"> <?php include('/content/'.$_GET['page'].'.php'); ?> </div> This all works very fine, but my problem is, can I have a include inside an already included page? I would like to have a menu on my products.php site, but that page is already included from above, and i would like the menu on the products.php site to stay as the content from the nested include changes with input from the /products folder. my idea was something like this. site/ index.php content/ frontpage.php products.php contact.php products/ product1.php product2.php the HTML on the index.php is the same as above and then i would add the include() on the products.php page, so its kinda the same thing, but one inside the other. HTML inside the products.php folder <div id="sub_menu"> <ul> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> </ul> </div <div id="sub_main"> <?php include('/content/products'.$_GET['#'].'.php'); ?> </div> I dont know how to link to the new files so they will be included while the first include still stays on the page. Any of you know how and if this can be done? Or maybe at better way to do it? Hope this made sense, my first PHP question Thanks Hi guys, Happy New Year http://www.phpfreaks.com/forums/php-coding-help/?action=post How can i get the path http://www.phpfreaks.com/forums thanks, Hey guys! I just joined this forum today, and I'm wondering about something... I see a lot of sites, and in the code of the site, style sheets and javascript includes are references in a manner similar to this... "href='http://www.somesite.com/css/css.php/someDirectory/style.css'" How is this done? The path following the "css.php" is what confuses me. Thanks for any information you have! I am trying to find the URL to a directory TWO levels above the script level (if you know what I mean). For example.. the script sits at Code: [Select] http://www.domain.com/TestArea2/members/index.php BUT I need to find the path to Code: [Select] http://www.domain.com/TestArea2/ the nearest I get is... $domain = $_SERVER['HTTP_HOST']; $domain .= $_SERVER['REQUEST_URI']; echo $domain; // outputs www.domain.com/TestArea2/members/index.php Is there a simple method to do this or have I got to split the string and work backwards? Many thanks It's the simple things that frustrate me sometimes. My project has a one root folder. Under that are three separate folders (admin, img, and inc). "admin" contains admin pages, "img" contains images, and "inc" contains utility files to be included and used by other scripts. I'll just take one specific problem as an example. In my inc folder is a file called "send_email.php". It needs to include another file called "class.phpmailer.php" in the same directory (inc). Now, since these files are never called directly but included by scripts in the rest of the project, I cannot simply do "require('class.phpmailer.php')". I have a file in the base project directory called validation.php. It needs to include inc/send_email.php to use its functions to, obviously, send email. Now, that part is no problem. I just require('inc/send_email.php') since that is a valid path from validation.php. My problem comes when send_email.php tries to include class.phpmailer.php. As I said before, I cannot just directly include it without any path since it's not being called directly. It "inherits" the path of the file that called it so just a direct require to it. My "solution" was to add a config value called "path" to my config file in the root directory. It would ideally hold the path from the server root to my project folder. In my case I set it to "/danny/smswebalerts/" which is indeed the correct path from my web root. I use $config['path'] to link to my images and CSS files and it works correctly. I thought it would solve my problem when I did the following in send_email.php: require_once($config['path'] . 'inc/class.phpmailer.php'); That indeed correctly builds the full path to that file: /danny/smswebalerts/inc/class.phpmailer.php. When I open up a page that includes send_email, however, I get the following error: Code: [Select] Warning: require_once(/danny/smswebalerts/inc/class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in /home/danny/workspace/smswebalerts/inc/send_email.php on line 20 I would appreciate if somebody could give me some nice solution before I just say "screw it" to organization and plop everything in the same directory. It's really frustrating that my project is being held up by some technicality like this. Hi, I want to get root path and use on links even if i'm in sub to sub folder etc... suppose my site name is fitness.com and having two subfolder. so url will become http://www.fitness.com/dir/dir_sub here i want to put a link to go to root directory file. there are different ways to do that. e.g: Code: [Select] <a href='../../filename.php'>go to that page</a> but i want to use some constant that always shows to root directory. as i defined here Code: [Select] define("SERVER_NAME" , $_SERVER['HTTP_HOST']); //and used it like this <a href='<?php echo SERVER_NAME; ?>/filename.php'>go to that page</a> it works when we're on root directory. but when we go to sub directory it added sub directory name with it. which i don't want. is there any way? Thanks Im having a strange path problem. The problem is that in the base directory, i have some php files. These goes well. I also have two folders: one for my function library, and other for some type of webpages. My problem is that if i changue to a webpage in that folder through the menu in the base directory the path itself it also changues, so it became that directory. Base dir: tr Library directory: lib Category dir: categorias (these two are in tr, and tr in www of wamp) If i echo a link like this in some page that is in the tr directory: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> And i go to that web, the include path changues, so it became categorias. I use functions to echo the menu each time, so, it dont work because it uses the relative path, so, if i echo this again: <li><a href="categorias/listar_memoria_ram.php">List RAM Memory</a></li> the url thas is finally called in the web explorer is: http://localhost/tr/categorias/categorias/listar_Memoria_Ram.php That dont exist. Note also that all my web functions are in a file that exists in the lib library and thats included each time using this: include_once '/../lib/lib_inventario.php'; That file have a impMenu function that is used each time, and all the others. What i was seeking if a plain way of controlling the path so it became more simplier and i could just use a single path, without exceptions. Or at least an explanation that why these happens. Ask for whatever any extra information you need. |