PHP.ini include_path on windows with different drives - php

I try to include PHP file from different places of my computer. So I have defined different include paths in my php.ini
include_path=".;C:\project\a;X:\project\b"
When I try to include a file X:\project\b\file_b.php from a PHP script on C:\project\a\file_a.php with
require_once("file_b.php");
or with
require_once("X:\project\b\file_b.php");
I get the error
Warning: require_once(X:\project\b\file_b.php): failed to open stream: No such file or directory in C:\project\a\file_a.php on line 2
Fatal error: require_once(): Failed opening required 'X:\project\b\file_b.php' (include_path='.;C:\project\a;X:\project\b') in C:\project\a\file_a.php on line 2
Abort Processing during Fatal-Error: require_once(): Failed opening required 'X:\project\b\file_b.php' (include_path='.;C:\project\a;X:\project\b') Error in Script C:\project\a\file_a.php on Line 2
I have tried everything I can do with my knowlegde, but nothing works.
I hope, that someone can hlep me with solving this problem. Is there a problem with include paths on different drives on a Windows system?
Best regards,
bition

After a long time, I have finally the answer for my special problem.
It is really ery special, because I use BoxCryptor to encrypt my D: drive. BoxCryptor creates the virtual device X:, but it is not present for Apache and PHP. But I can configure BoxCryptor the mount the device X: as a rwal harddrive. After I set this, everythings works fine.
Sorry for the confusion about my vortual and real harddrives and thank you for your help!
Best regards,
bition

I have found with WAMP etc in the past, that using backslashs works. Just dont encapsulate the string with double quotes "C:\path", this will process the contents as #Marc B warns. Instead encapsulate the string with single quotes 'C:\path' and then the contents are not processed.
If the backslashes in the contents of the single quote string are still being processed, try the following.
<?php
$path = 'X:/project/b/file_b.php'; // PATH WITH FORWARD SLASHS
$path = str_replace(chr(47) ,chr(92) ,$path); // REPLACE FORWARD WITH BACKWARD SLASHS
require_once($path); // RUN FILE
?>

Related

Zend include_once(myphpfile): failed to open stream: No such file or directory

this problem is driving me nuts. I know similar problems has already been submitted but no solution worked for me
I'm getting this error:
Warning: include_once(): Failed opening
'Recruit/Model/DbTable/Volontari.php' for inclusion
(include_path='/var/www/html/fabio/recruit/application/../library:/var/www/html/fabio/recruit/library:.:/usr/share/pear:/usr/share/php')
in /usr/share/php/Zend/Loader.php
But actually file exists on server. This is part of my folder tree
source
|__application
|_ ....
|__library
|__Recruit
|__Forms
| |__VolontariCreate.php
|__Model
|__DBTable
|__Volontari.php
Form VolontariCreate.php works, so I don't think it can't find the path.
I also checked include paths with echo get_include_path();
and they're correct
If it can help, client is Ubuntu, server is Centos, zend version is 1.12.17dev
Thanks for your support.
I believe your problem is that linux/unix file systems are case sensitive. On servers running Windows you can get away with whatever file case you fancy as they are case insensitive. As such your request to include:
Recruit/Model/DbTable/Volontari.php
Will fail because the actual path should be:
Recruit/Model/DBTable/Volontari.php
Notice the capital B in DB...

get around allow_url_include=0 error

I am trying to include a file from a url, however I get the following error thrown up.
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Warning: include(http://localhost/diningtime/templates/100/index.php): failed to open stream: no suitable wrapper could be found in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Warning: include(): Failed opening 'http://localhost/diningtime/templates/100/index.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.4/lib/php') in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Test
Just wondering if there is anyway around this?
My PHP include code is
<?php include "$location/index.php"; ?>
I appreciate your help on this.
You're using a full URL as you include path, which tells PHP to attempt to do an HTTP request to fetch that file. This is NOT how you do this. Unless that ...100/index.php outputs PHP code, you are going to get some HTML or whatever as the include result, NOT the php code in the file. Remember - you're fetching via URL, which means it's an HTTP request, which means the webserver will EXECUTE that script and deliver its output, not simply serve up its source code.
There's no way for the webserver to tell that the HTTP request for that script is an include call from another PHP script on the same server. It could just as easily be a request for that script from some hacker hiding in Russia wanting to steal your source code. Do you want your source code visible to the world like this?
For local files, you should never use a full-blown url. it's hideously inefficient, and will no do what you want. why not simply have
include('/path/to/templates/100/index.php');
instead, which will be a local file-only request, with no HTTP stage included?
I have had a similar issue.
Considering 'Marc B's' post, it is clear that using absolute URLs is not a great idea, even if it is possible by editing the php.ini as 'ficuscr' states. I'm not sure this workaround will work for your specific situation as it still requires adjustments to each page depending on where it is in your folder structure, but it does makes things simpler if, like me, you have a lot of includes in your website.
<?php $root="../";?>
<?php include($root . 'folder-A/file_to_be_included_1.php');?>
<?php include($root . 'folder-A/file_to_be_included_2.php');?>
<?php include($root . 'folder-B/file_to_be_included_3.php');?>
<?php include($root . 'folder-B/file_to_be_included_4.php');?>
<?php include($root . 'folder-B/sub-folder/file_to_be_included_5.php');?>
For me, this means if I move a page to another location in the folder structure, for example in a sub-folder of its current location, all I need to do is amend <?php $root="../";?> to become <?php $root="../../";?> for example

PHP Fatal error: require_once(): Failed opening required 'Zend/Gdata/Extension.php'

For some strange reason I cannot figure out right now, NoEmbed.php fails with a fatal error when trying to include a file. include path is set correctly, I've verified that like below (right before the require_once directive in NoEmbed.php):
$s = ini_get('include_path');
$a = explode(':',$s);
foreach($a AS $path) {
echo $path;
if(file_exists($path.'/Zend/Gdata/Extension.php')) echo '...found<br/>';
else echo '...not found<br/>';
}
which outputs "found" within the location expected.
I must admit that I'm currently unable to think of any reason why this should happen, especialy since NoEmbed.php is included correctly. I've encountered similar problems with caching solutions, but they've all been deactivated or uninstalled by now without making any difference.
Edit: I just found that it works with "require" vs "require_once" (then throwing a redeclare error)... any possible reason for that?
Check the permissions and owner of the repertory where are the files, and the files ones two.
for instance dir could be 755 and files 644, with www-data as owner if you want to write into them.
In my case, the problem was faulty hard drive. I could see the file and its contents with terminal, yet PHP gave me this specific file not found error in 60% of hits.
I have moved it to another hard drive and the error disappeared.

Cannot include a file in php

I am running the code below in some if/else statements, I have a weird issue in the same file this exact code below works fine, however in another area if it is called I get this error;
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\webserver\htdocs\processing\process.friends.php on line 168
Warning: include(http://localhost/index.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\webserver\htdocs\processing\process.friends.php on line 168
$_SESSION['sess_msg'] = 'Please Enter the Correct Security Code';
$_GET["friendid"] = $friendid;
$_GET["p"] = 'mail.captcha';
$_GET["f"] = 'friend';
include ("index.php");
exit;
And just to clarify I am njot trying to run this code 2 times at the SAME time, it's more like this; Not just like this but you get the point that they are not run at the same time
if(something){
run the code above
}else{
run the code above
}
If it matters, I am currently running a LAMP setup on a windows PC
remove the "http://localhost" part of your code. As a rule of thumb, when you include your own files, you should include them from your file system.
include "./index.php";
Just remove the http://localhost/ part and you'll be okay.
Well, I don't kow the answer to your question, though I do have to ask why you feel the need to include a URL based file?
include('http://whatever.com/'); can be EXTREMELY dangerous.
If you're just trying to output the HTML generated from that, I'd suggest you do something like echo file_get_contents('http://some/url');. If you're trying to include PHP code, use the system path
Are they EXACTLY the same? Could you post both versions of the code?
I can also recommend not doing an include('http://...'); This will make PHP to an HTTP request to your webserver, and grab the result. You might be a bit better off just doing include('index.php');, if this is possible for your setup.
Is allow_url_fopen enabled in php.ini?

PHP "require_once" says it can't find a file in the directory

I'm debugging some PHP code written by an outsourcing company (I'm not a PHP guy at all but know the basics; we have an offshore team of PHP developers working for us on this project) that's not working; the code is supposed to be called every 30 minutes by a cron job but its not firing. I tried to run the PHP script via the command line to test if it's working, but it's giving me the following (anonymized) errror:
PHP Fatal error: require_once(): Failed opening required '/myapp/_lib/_classes/MySql.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/myapp/_lib/_base/common.inc.php on line 6
However, the file /var/www/html/myapp/_lib/_classes/MySql.php exists under the proper directory. I'm missing something simple, I'm sure, but like I said I know really nothing beyond the bare basics of PHP and I really need to get this service up and running.
EDIT: The code is using the __autoload() function with all classes in /_lib/_classes
if you start a file name with a slash, it means it's an absolute path. try instead:
require_once('/var/www/html/myapp/_lib/_classes/MySql.php');
Case sensitivity maybe? I've had that problem before.
I'm guessing it's a permissions issue - make sure both your account (for testing purposes) and whatever account cron is going to run your script under (quite possibly yours, but maybe a different one) have read privileges on the file.
Also: the path for the include says /myapp/_lib/_classes/MySql.php, whereas it exists in /var/www/html/myapp/_lib/_classes/MySql.php. Can you change the include to reference the full path?
As said, casing and in addition the correct permissions to access that file are needed.

Categories