adding own library in drupal - php

i want to include a php file .module file like this using hook_init
function drupsocial_init() {
require_once base_path().(drupal_get_path('module', 'drupsocial') . '/libraries/dsinvoke.php');
}
but showing this error
Fatal error: require_once() [function.require]: Failed opening required '/drupal6/trunk/sites
/all/modules/drupsocial/libraries/dsinvoke.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs
\drupal6\trunk\sites\all\modules\drupsocial\drupsocial.module on line 32
how can i include such file

You normally can include any file if you know the full path of the file and the file is accessible. Check the path to the library, correct it and you should not have any problem.
Start with the full path to the file first. If that works, you can think about using a dynamic path to the file.

why drupal trying to load the file in the trunk directory ? are you working on a svn repo ? i think there's something wrong with that path.
I also suggest you to check permissions
Hope this helps

Related

Cannot set PHP include_path

I have uploaded all my files in var/www/html and in one of my php files I have this line :
require_once('libraries/stripe/init.php');
the structure of my folders are list this:
www
-html/
-libraries
-> Stripe -> init.php
-register.php
I keep getting this error message:
Warning: require_once(libraries/Stripe/init.php): failed to open stream: No such file or directory in /var/www/html/register.php on line 116
Fatal error: require_once(): Failed opening required 'libraries/Stripe/init.php' (include_path='.:/usr/share/php:/var/www/html/') in /var/www/html/register.php on line 116
my php.ini file used to be like this
include_path= ".:/usr/local/php/pear/"
but based on some answers here i changed it to
include_path='.:/usr/share/php:/var/www/html/'
but it's not working!
Edit: in my libraries folder I have file called index.php the content is:
<?php
header("Location: ../"); die();
I wouldn't leave library paths to chance like that:
require_once(__DIR__ . '/libraries/Stripe/init.php');
This would make sure you include the script using the absolute directory path of the currently running script.
Update
Failed opening required '/var/www/html/libraries/Stripe/init.php'
Well, then the file is simply not there; if this file was generated by some other tool, e.g. composer, it would need to be done again on a new server (or ideally at every deployment).
i think the problem is my Stripe folder is in "s" but I'm using capital "S". is there anyway to make not case sensitive?
File systems under Linux are case sensitive by default (not even sure whether it can be changed) as opposed to Windows. Make sure you use capitalisation consistently.
That not what you are looking for. it says that php.ini file can't find the path of the file that you specified. that's why you should use absolute path to the file
require_once "path/to/file";

PHP require warning says "no such file" even though the warning traces out the correct file path

I am trying to require a file in a different folder, but php keeps saying the file does not exist.
"Warning: require_once(./include/config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\MyProject\include\members.php on line 2"
Other pages have been able to access this file without issue, but when it's in the scripts folder instead of the home folder or the include folder, it says the file does not exist. The path that is output in this error is correct, so why is it failing?
if you need to back use ../
For example: require_once("../include/config.php")
Alright, I found the problem. The issue was actually an require within the file I was trying to include. I guess since the required file was being called outside of its folder, I had to include the full file path for the file that the required file was requiring.
This might be a sign that I have too much spaghetti-code... Thanks for all the help though. :)

php configuration error

My php files were working fine but today when i check them i get following errors.
Warning: require_once(Connections/deal.php) [function.require-once]: failed to open stream: No such file or directory in C:\complete project\ordering system\orderingcart.php on line 1
Fatal error: require_once() [function.require]: Failed opening required 'Connections/orders.php' (include_path='.;C:\php\pear') in C:\complete project\orderingcart.php on line 1
I don't know how to resolve these errors, where do I start?
It means, the path you gave in require_once() is invalid. You have two options,
1.Checkout whether the path Connections/deal.php is correct or not. Do you have a folder Connections in the folder where this running file is placed? Is there a deal.php inside that folder Connections?
I think your running file path is C:\complete project\ordering system\orderingcart.php. It does not have such a folder and file. So place your Connections folder in C:\complete project\ordering system\ and checkout.
2.Else, You can run the page without fatal error if you change the line to include_once(Connections/deal.php). Functions assosciated with deal.php will be inactivated.
This sounds like the file has either moved OR the file permission have been altered as to prevent the server account (usually www-data) from having access to it.
You might also have better luck by trying to access the file by suppling an absolute path, rather than a relative path, e.g:
<?php
$lines = file("C:\\Documents and Settings\\myfile.txt");
foreach($lines as $line){
echo($line);
}
?>
This file path issue give full file location like
if it is windows
require_once('C:/complete project/Connections/deal.php');
For reference
http://php.net/manual/en/function.realpath.php

Include statement in php file

I have a php file (php1.php). Within that php file i have the following line:
include('php/PROTECT/login.php')
However when i load the page i get the following error:
Warning: include(php/login.php) [function.include]: failed to open stream: No such file or directory
it just totally ignores the /PROTECT/ section?
Does anyone have any ideas why this is and how i can resolve the issue?
My file structure is as follows: (php1.php is within /php and login.php is within /php/PROTECT
It should look like:
include('php/PROTECT/login.php');
Make absolutely sure that that's the include call that's throwing the error. Make sure that no other code, in php1.php or in any file it has included or required tries to include php/login.php.
If php1.php is within /php/ (which I understand it to be), then you will need to use the following:
include('PROTECT/login.php');
Includes in includes can be a bit messy, but if you concatenate with DIR it is easier. DIR is always path to the file it self, if you use DIR you can always use the relative path. Like this:
include DIR . "/PROTECT/login.php";
As you can see by the error message:
Warning: include(php/login.php)
"PROTECT" is excluded from the path, probably for being in all caps.
Change the directory to all lowercase ("protect" or similar) and see if you get the same error.

Why do I get a Warning and a Fatal error when I use ../?

When I use ../mysqlConnect.php I get the following messages.
Warning: require_once(../mysqlConnect.php) [function.require-once]:
failed to open stream: No such file or directory in /home/content/etc...
Fatal error: require_once() [function.require]: Failed opening required
'../mysqlConnect.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/etc...
When I use the directory name - mydir/mysqlConnect.php - everything works fine.
require_once('../mysqlConnect.php') asks PHP to look in the directory above the one your script is currently in for mysqlConnect.php.
Since your connection file appears to be in a mydir directory, require_once('mydir/mysqlConnect.php') works because it looks in that directory, which is contained by the one it's currently in.
Visual representation (assuming script.php is your script including that file):
dir/
subdir/ # PHP looks here for ../mysqlConnect.php
script.php
mydir/ # PHP looks here for mydir/mysqlConnect.php
mysqlConnect.php
Require is relative to the invoced script, not the script you call require() in. Use something like this to have an absolute path:
require(dirname(__FILE__) . '/../mysqlConnect.php');
In PHP 5 you can also use DIR.
because it doesn't find your file then. to give a more specific answer I need to see you file-/folder-structure
That's because you are not specifying the correct include path. ../ refers to parent directory. ../../ goes two directories back, ../../../ goes three of them back. If the mysqlConnect.php file is present in the same folder as your script, you don't need to specify ../ in the include.
Make sure that you specify the correct path. You can easily check whether or not you are specifying correct path like:
if (file_exists('../mysqlConnect.php'))
{
echo 'Iam specifying the correct path !!';
}
else
{
echo 'Well, I am not :(';
}

Categories