I keep getting an error when I try to include simpletest in my include_path:
<?
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(basename(dirname(__FILE__)) . '/../../'));
include 'simpletest/autorun.php';
returns:
.:/usr/lib/php:/Users/kristiannissen/Documents/php
Warning: require_once(/Users/kristiannissen/Documents/php/simpletest/arguments.php): failed to open stream: No such file or directory in /Users/kristiannissen/Documents/php/simpletest/reporter.php on line 13
Fatal error: require_once(): Failed opening required '/Users/kristiannissen/Documents/php/simpletest/arguments.php' (include_path='.:/usr/lib/php:/Users/kristiannissen/Documents/php') in /Users/kristiannissen/Documents/php/simpletest/reporter.php on line 13
personally your view pages are the first executed, such as index.php and view pages should always be in the root of your html.
so within index.php you can do:
define("BASE_PATH",str_replace("\\","/",dirname(__FILE__)));
so now BASE_PATH would be equal to: /Users/kristiannissen/Documents/php/simpletest
So if you want to phpdirectory in your include path you should use dirname() to go UP a directory:
//Get an array of your include paths
$include_parts = explode(PATH_SEPARATOR,get_include_path());
//Extend the paths
$include_parts[] = dirname(dirname(BASE_PATH)); //this is ../../
//recompile the paths and set them
set_include_path(implode(PATH_SEPARATOR,$include_parts));
this is the safe way to accomplish what your trying to do.
There is an alpha2-release on sourceforge that has the arguments.php-require commented out. I guess it isn't needed anymore.
Related
I get this error when I try to call product_class.php in index.php. My product_class.php works fine, but when I try to add it to index this error show up:
Warning: require_once(../Includes/config/general.php): failed to open stream: No such file or directory in D:\Programming\Web\xampp\htdocs\android-api\product\product_class.php on line 2
Fatal error: require_once(): Failed opening required '../Includes/config/general.php' (include_path='D:\Programming\Web\xampp\php\PEAR') in D:\Programming\Web\xampp\htdocs\android-api\product\product_class.php on line 2
here my code at index.php
<?php
require_once('product/product_class.php');
require_once('Includes/config/general.php');
require_once INCLUDES_DIR.'/database.php';
?>
Make sure you specify the correct file path. If the index.php file and the product or Includes folder are in the same folder, try this:
require_once __DIR__ . '/product/product_class.php';
require_once __DIR__ . '/Includes/config/general.php';
I'm having problem with include() and require_once() this is what I have on my script on report-publisher file that resides here :
C:\xampp\htdocs\checklists\reports\report-publishers.php
now i want to include this file:
<?php include("images/report-publisher-completed.php");?>
and the directory of that script is here:
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
it works the problem is in this report-publisher-completed.php i have the following:
require_once("../../includes/database.php");
here is the location of that file: C:\xampp\htdocs\checklists\includes\database.php
so when i run the code I get the following error:
( ! ) Warning: require_once(../../includes/database.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
on line 3
( ! ) Fatal error: require_once(): Failed opening required
'../../includes/database.php' (include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\checklists\reports\images\report-publisher-completed.php
on line 3
How can I fix this issue?
Thanks!
Try like this
require_once(dirname(__FILE__).'/../../includes/database.php');
The safer way to include a file is to use a relative path from the current script, using the constant __dir__, like this :
include __dir__ . '/includes/database.php';
So, for your case, probably :
include __dir__ . '/../../includes/database.php';
Try this
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/database.php";
Instead of
require_once("../../includes/database.php");
I am running wamp64 to locally host my website (it is a vbulletin forums used for testing if that helps at all).
I am trying to create a new webpage that is located in a subfolder instead of the root of the website, however I am running into errors.
The webpage I am trying to create is the index.php webpage inside of the addons folder.
My file structure is:
C:
-wamp64
--www (website root)
--global.php
---addons
----index.php
----images
---includes
----config.php
The code I am using for addons - index.php is:
<?php
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'addons');
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array(
'ADDONSTESTPAGE'
);
$actiontemplates = array();
require_once('/../global.php');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('ADDONSTESTPAGE') . '");');
?>
When I create a new page in the www folder, it works perfectly (except I use require_once('/global.php'); instead of require_once('/../global.php');.
However, because this is in a subfolder, I am running into the following error due to the files that the global.php is requiring once having their own require_once functions inside of them and those files have their own require_once functions inside of them, etc.
Here is the error I am getting now when I go to localhost/addons/:
Warning: require_once(C:\wamp64\www\addons/includes/init.php): failed
to open stream: No such file or directory in C:\wamp64\www\global.php
on line 20
Fatal error: require_once(): Failed opening required
'C:\wamp64\www\addons/includes/init.php'
(include_path='.;C:\php\pear') in C:\wamp64\www\global.php on line 20
Here are lines 13-20 of global.php:
// identify where we are
define('VB_AREA', 'Forum');
define('CWD', (($getcwd = getcwd()) ? $getcwd : '.'));
// #############################################################################
// Start initialisation
require_once(CWD . '/includes/init.php');
How do I solve this without messing up other files that use the global.php file? I have heard realpath is a common solution for this, but I am new to php and not exactly sure how to use it in this scenario.
All help is appreciated, thank you very much, if you need any more information feel free to ask!
Okay I was able to solve that error by changing require_once(CWD . '/includes/init.php'); to require_once(__DIR__ . '/includes/init.php');.
Now I am getting this error:
Warning: require_once(C:\wamp64\www\addons/includes/class_core.php): failed to open stream: No such file or directory in C:\wamp64\www\includes\init.php on line 51
Fatal error: require_once(): Failed opening required 'C:\wamp64\www\addons/includes/class_core.php' (include_path='.;C:\php\pear') in C:\wamp64\www\includes\init.php on line 51
Class_core.php exists in the includes folder.
Line 51 of init.php is:
require_once(CWD . '/includes/class_core.php');
I tried changing it to require_once(__DIR__ . '/includes/class_core.php'); but it breaks the entire website.
global.php assumes the server process is running from the main C:/wamp64/www directory but because you are running from the addon folder, CWD will be set to C:/wamp64/www/addon , hence all the errors.
To resolve this, do, in your index.php
1) Revert all the changes you have made to VBulletin in your global.php and init.php etc...
2) set your current working directory to the root directory, you can use chdir('../') at the top of index.php before any require_once
3) require global.php in your index.php require_once('global.php');
Step 2 works because now php now sees the root directory as the working directory.
What I have done:
) Downloaded Swift-4.1.5.tar
) Extracted it
) Uploaded to my host in /public_html/domain/lib using FileZilla
) Made a new script using the code below.
) Opened it in the Browser and I got the following error below
So my question is, how am I getting the error that the file doesn't exist if It's 100% there? Thanks!
<?php
require_once '/public_html/domain/lib/swift_required.php';
?>
Warning: require_once(/public_html/domain/lib/swift_required.php) [function.require-once]: failed to open stream: No such file or directory in /home/myuser/public_html/domain/email.php on line 5
Fatal error: require_once() [function.require]: Failed opening required '/public_html/domain/lib/swift_required.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/myuser/public_html/domain/email.php on line 5
Here's a screenshot of my dir from FileZilla.
http://i.imgur.com/Zsy8y.jpg
This is wrong:
// this is absolute path, just like /home/user or /var/www
require_once '/public_html/domain/lib/swift_required.php';
Use instead:
// this is relative path to the current file
require_once 'public_html/domain/lib/swift_required.php'; //notice: no '/' in the beggining
OR:
// so use this one if you know the whole path to the file
require_once ABSOLUTE_PATH_TO . 'public_html/domain/lib/swift_required.php';
OR:
// or use this one if you don't know the whole path
// or if the path will change (dev machine and production machine)
require_once dirname(__FILE__) . RELATIVE_PATH_TO . 'public_html/domain/lib/swift_required.php';
I have a file header where i have created variables for all the paths i need, like this:
$GLOBAL_stylePath = "http://localhost/pspace/css/";
(if i shouldn't use http in the above, then how would it be? C://htdocs/xampp/pspace/css/ ???)
include_once "/classes/authorizationUtils.php";
$authorizationUtils = new AuthorizationUtils();
anyways, the includes are messing up everything and giving me errors such as:
Warning: include_once() [function.include-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\xampp\htdocs\pspace\includes\header.php on line 12
how can i enable this configuration in my php.in. i have a variable allow_url_include=off, when i "on" it, no changes happen. and also this:
Warning: include_once() [function.include]: Failed opening 'http://localhost/pspace/classes/authorizationUtils.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pspace\includes\header.php on line 12
Make sure that you editing the correct php.ini file. Usually there are two php.ini files associated with your installation. One is used for the command line interface php and the other for the server side php. Make sure that you make the changes to both.
Make sure that you restart your webserver after these changes are made.
This warning :
Warning: include_once() [function.include]: Failed opening 'http://localhost/pspace/classes/authorizationUtils.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pspace\includes\header.php on line 12
it means that you try to include file which could not be found in include_path. So, what you need is to define your include_path.
If your directory listing is like this :
c:\xampp\htdocs\pspace\ // as your root
c:\xampp\htdocs\pspace\includes\
c:\xampp\htdocs\pspace\classes\
Try this :
<?php
$path1 = '.\includes\';
$path2 = '.\classes\';
set_include_path(get_include_path() . PATH_SEPARATOR . $path1 . PATH_SEPARATOR . $path2);
?>
Your also can change relative path $path1 = '.\includes\'; to absolute path $path1 = 'c:\xampp\htdocs\pspace\includes\';
Read this to understand more about set_include_path and about include function that always include files based on file path given. Hope this can help.