I want to fetch div element from other website .
on which iam having my profile, i have tried using this code.
require_once('../simple_html_dom.php');
$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);
but this code is giving errors
Warning:
require_once(../simple_html_dom.php)
[function.require-once]: failed to
open stream: No such file or directory
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
Fatal error: require_once()
[function.require]: Failed opening
required '../simple_html_dom.php'
(include_path='.;./includes;./pear')
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
iam stuck with this plz help me with the code snippets for fetching the specific div element from a website
The file simple_html_dom.php is not where you're telling PHP to look for it.
require_once('../simple_html_dom.php');
To be safe, try using the full path instead of a relative path.
require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
BTW, if the full path above is incorrect, then that is your problem. This is the path that PHP is trying.
To clarify: I'm only suggesting the OP switch to absolute paths to identify and confirm the source of the issue. Going to production with absolute paths is rarely a good idea.
require and include paths can be tricky in PHP. Try to use full paths when you can. You'll find $_SERVER['DOCUMENT_ROOT'] usefull for that.
Your inlude_path should contain ".", which means current directory.
But if you having troubles with including file by relative name, then just try to use absolute names, like require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
But better it should be:
require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';
Related
this is kind of a silly question, but as I can't sort it out I thought it might be good to get some help. The point is that the ".. /" to go back directory is not working.
The file I'm executing is in a folder that's on the main route and I need to go back to the main route and then enter another folder to load this other PHP file but it's not working what could be causing this issue.
ERRORS:
Warning: require_once(../PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in things/public_html/classes/Mail.php on line 3
Fatal error: require_once(): Failed opening required '../PHPMailer/PHPMailerAutoload.php' (include_path='.:/opt/alt/php71/usr/share/pear') in things/public_html/classes/Mail.php on line 3
DIRECTORY STRUCTURE:
File where the requiere once is:
/public_html/classes/filethatwantstoacces.php
File where it wants to get:
/public_html/PHPMailer/PHPMailerAutoload.php
require_once('../PHPMailer/PHPMailerAutoload.php');
What you should be using is the $_SERVER['DOCUMENT_ROOT'] variable. Please read this answer to another question for details.
If you are using PHP you should get into a habit of NOT using relative file paths at all but to use absolute paths, which will guarentee to succeed every time (As long as the target file exists and is reachable, etc.).
so; use $_SERVER['DOCUMENT_ROOT']
As a side note, you do not need to use brackets for your includes/requires, it's simply giving the server more work to do for no extra benefit.
The $_SERVER['DOCUMENT_ROOT'] is the base directory of your PHP/web application, typically the contents of the folder /public_html.
Using correct syntax and the above $_SERVER value (which will point to the /public_html folder you will have:
require_once $_SERVER['DOCUMENT_ROOT'].'/PHPMailer/PHPMailerAutoload.php';
This will work from any script within your directory structure, if the file (PHPMailerAutoload.php) exists and is reachable at that given location
Given your location
/public_html/classes/filethatwantstoacces.php
doing ../ gives you
/public_html/classes
so ../PHPMailer/PHPMailerAutoload.php evaluates to
/public_html/classes/PHPMailer/PHPMailerAutoload.php
As #Martin has pointed out, using $_SERVER['DOCUMENT_ROOT'] to construct an absolute path to your file is the easiest way to avoid relative directory navigation errors such as this:
require_once $_SERVER['DOCUMENT_ROOT'].'/PHPMailer/PHPMailerAutoload.php';
This is the problem I am facing now Can you please suggest me to get rid of this problem. Before I have not get this problem It was working nicely now I don't know what happened the path is correct only. Anyone please solve it...
Warning: include(../includes/db.php): failed to open stream: No such
file or directory in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3
Warning: include(): Failed opening '../includes/db.php' for inclusion
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3
Warning: include(functions.php): failed to open stream: No such file
or directory in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4
Warning: include(): Failed opening 'functions.php' for inclusion
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4
Based on the error posted, it seems to be that the include_path is referring to the path (include_path='C:\xampp\php\PEAR') while the PHP files are included in some other folder.
You need to update the include_path variable to point to the correct location. You can find this in the php.ini file.
Computers don't lie, if it says it doesn't see it, then it is not there
Make sure you are making it look at the right place, and if I will advise you do it manually also to confirm
I also suspect it is an issue arising from using relative paths. Please make sure the path is right considering where you are currently calling the file from
e.g calling include(../includes/db.php) from index.php is different from calling it from admin/index.php
EDIT
If your are calling from C:\xampp\htdocs\portfolio\admin\includes\admin_header.php to C:\xampp\htdocs\portfolio\includes
then
include(../../includes/db.php);
is the right syntax to use
Hope this Helps
I have had this the same issue before and it ended up being something dumb on my part i forgot to start the MySQL on the XAMPP control panel. I'm sure i'm late the the party on the answer but hope it can help someone later down the road.
a bit late but i just reply for those who might get the same error .
assuming you are storing header.php in your includes directory and its not beside your index.php,so when you include bd.php into your header.php and then including your header.php into your index.php pay attention that apache knows index.php direcotroy as your pwd so if you have set that relative path for db.php based on header.php directory its not gonna work.you can use absolute path to avoid this or just set you relative path based on relative location of db.php from index.php
It look likes, the files you are trying to include in your php codes, are not on that place. Try to save all your include files in a particular folder and then call it wherever you want to call it.
suppose your index.php file is in xampp/htdocs/your_folder_name/index.php , then simply create a folder name whatever you want to name it inside your folder name your_folder_name/your_new_folder and save all your files which you want to include, as if you are saving db.php then call it on the top of your page as:
<?php include("your_new_folder/db.php");?>
This has to do with how you are coding your relative path.
I am assuming you got this error when your app made reference to admin_header.php, which has an include() to try and call {document_root}/porfolio/admin/includes/db.php. My educated guess is it contains your implementation of the connection string to the database.
The correct relative path should be: include('../../includes/db.php');
This link should give you a better understanding of relative paths (and paths in general).
https://phpdelusions.net/articles/paths
In case this helps anyone else, I had this problem and then realised WAMP had crashed (or maybe I didn't start it). Either way, WAMP wasn't running on my local machine, so... doh.
This should be the very first thing you check (in line with, "is it plugged in?").
Try removing relative paths ("../")
e.g. change include(../includes/db.php) to include(includes/db.php)
I have a problem with include path in PHP.
Code:
https://github.com/kukubaczek/KukuShop/blob/master/www/panel/index.php
If i open the panel/index.php page I see this error's:
Warning: require_once(/parts/header.php): failed to open stream: No
such file or directory in /PATH/KukuShop/www/panel/index.php on line 3
Fatal error: require_once(): Failed opening required
'/parts/header.php' (include_path='/..') in
/PATH/KukuShop/www/panel/index.php on line 3
How can I fix this? Here is problem with include path.
You are using absolute references when you probably want relative file locations. Try using this instead:
require_once("../parts/header.php")
What does the directory structure look like?
The set_include_path('/..'); statement doesn't seem to make sense.
Your PHP installation can't seem to find the files.
I am trying to run 2 example of PHPExcel
01simple-download-xlsx.php and 07reader.php
01simple-download-xlsx.php Working Perfect but this example 07reader.php is showing error mentioned below Why can't understand since last 4 hours.
Any one can kindly tell me why this is happening when the file is using same directory structure.
Warning: require_once(../Classes/PHPExcel/IOFactory.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Fatal error: require_once(): Failed opening required
'../Classes/PHPExcel/IOFactory.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Some of the examples (such as the 01* files) correctly use an absolute pathname __DIR__ . '../Classes/...' to include the main PHPExcel library, which means you don't need to be in the /Examples directory to run them.
Other examples (07reader.php included) simply use a relative pathname '../Classes/...'to include the main PHPExcel library, which means you do need to be in the /Examples directory to run them.
To resolve the issue, either ensure that you're in the /Examples folder when you run these files, or modify the include to use the absolute pathname.
I believe I've now fixed all of these example files to use the absolute pathname in the development branch on github.
I've been programming in PHP for several years now and never encountered this error before.
Here's my widget.php file:
require_once('fruit.php');
echo "I am compiling just fine!!!";
And my fruit.php file:
$bVar = true;
When these two files look like this ^ then everything compiles with no errors and I get the "I am compiling just fine!!!" success message.
Now, the minute I move the fruit.php file one directory level up, and change my widget.php file to reflect the directory restructuring:
require_once('../fruit.php');
echo "I am compiling just fine!!!";
Now all the sudden, I get PHP warnings & fatal errors:
Warning: require_once(../fruit.php) [function.require-once]: failed to open stream: No such file or directory in /webroot/app/widget.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../fruit.php' (include_path='.:/usr/local/php5/lib/php') in /webroot/app/widget.php on line 1
In all my years working with PHP, I've never seen require_once() fail like this before. Any ideas?!?!
Maybe you are in the wrong work directory. Its a bad idea to rely on it (except you explictly want to access it) anyway. Use
require __DIR__ . '/../fruit.php';
or with pre-5.3
require dirname(__FILE__) . '/../fruit.php';
Remind, that paths starting with .., or . are not resolved against the include-path, but only against the current work directory.
Remember that in the second case, you're specifying a path, but in the first case it uses your includes path. Perhaps rather than explicitly specifying .. in the second case, you case modify your include path.
http://php.net/manual/en/function.set-include-path.php
I know the question is old, but it is still relevant.
In my experience, the "open_basedir" directive is most likely to cause this issue.
require_once('fruit.php');
This searches for fruit.php in the same directory as widget.php is in, no matter what the current working directory is.
require_once('../fruit.php');
This searches for fruit.php in a directory above the current directory, not in the directory above the one widget.php is in.