My development environment is: Win7, XAMPP 1.8.3.3 VC11.
include_path in my PHP.ini file is: ".;C:\xampp\php\PEAR"
I have downloaded a package simplehtmldom_1_5 and kept in "C:\xampp\php\PEAR" folder so that my test file "C:\xampp\htdocs\test1.php" can include PHP files from this package. My test1.php looks like:
<?php
include_once('simplehtmldom_1_5/simple_html_dom.php');
echo file_get_html('www.google.com')->plaintext;
?>
As soon as I type http://localhost/test1.php, I get the below error:
Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\php\pear\simplehtmldom_1_5\simple_html_dom.php on line 75
Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15
If I move the simplehtmldom_1_5 package from "C:\xampp\php\PEAR" to "C:\xampp\htdocs\simplehtmldom_1_5" and then try the above test1.php, I get the below error:
Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\htdocs\simplehtmldom_1_5\simple_html_dom.php on line 75
Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15
I have spent considerable time in debugging this but gave up now. Please help where I am wrong.
When using file_get_contents or similar function to open a URL you should specify the full protocol to tell PHP this is web address or external file not a local file.
Therefore,
file_get_contents('www.google.com')
Should be changed to:
file_get_contents('http://www.google.com');
You probably mean http://www.google.com and not a file called www.google.com
you need to use http:// with url
<?php
include_once('simplehtmldom_1_5/simple_html_dom.php');
echo file_get_html('http://www.google.com')->plaintext;
?>
also you need to check you have file dir(simplehtmldom_1_5) on where test1.php located
like :-
C:\xampp\htdocs\simplehtmldom_1_5
Related
I'm trying to execute "opendir" to understand how it works & use it in a recursive page call (I get wrong directories using .. & .).
My folder is constructed as follows:
C:\xampp\htdocs\Ask_Alansky
C:\xampp\htdocs\ is what comes in the XAMPP package, & Ask_Alansky is the folder in which I'm working.
The issue is simply that I cannot get a opendir () to work & open the directory. I'm not sure if I'm misunderstanding the concept, but I expect the code to simply open the folder "Ask_Alansky" & show me the files.
My code is:
<?php
opendir($_SERVER['C:/xampp/htdocs/Ask_Alansky'] . '/index.php');
?>
I get:
Notice: Undefined index: C:/xampp/htdocs/Ask_Alansky in
C:\xampp\htdocs\Ask_Alansky\php_main\Testing.php on line 14
Warning: opendir(/index.php,/index.php): The system cannot find the file specified. (code: 2) in
C:\xampp\htdocs\Ask_Alansky\php_main\Testing.php on line 14
Warning: opendir(/index.php): failed to open dir: No such file or directory in
C:\xampp\htdocs\Ask_Alansky\php_main\Testing.php on line 14
What I'm doing wrong?
$_SERVER is an associative array that contains multiple server information. Therefore, there is not such key C:/xampp/htdocs/Ask_Alansky. If you wish to access the current directory, use getcwd() instead. It is also not a good idea to use absolute path to your file, this will cause a problem when you migrate your app to another server.
I have recently been trying to add PHPMailer script to my site, following the accepted answer from here:
Send attachments with PHP Mail()?
I have never used a require statment before so I assume I must be doing it wrong, currently testing on my local host version of the site. I have downloaded the entire zip of git (unzipped it) and moved it to the dir my scripts are in.
In my script I added the following line:
require_once(__DIR__.'/PHPMailer-master/class.phpmailer.php');
Which to my understanding was all I needed to do to use it. However I get this error:
Warning:
require_once(C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php):
failed to open stream: No such file or directory in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Fatal error: require_once(): Failed opening required
'C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php'
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Any ideas what is causing this error? Am running PHP 5.6.21 if this is relevant.
Try to use the full path to the file, using realpath() - http://php.net/realpath, and use dirname(__FILE__) to get your current directory:
I am trying to make a login system for my app, and needed to use php for it. However I'm really new to php so I got errors. First of all, I am using a free web hosting for now, so it might be the issue here. That being said, here is the error part of my php:
<?php
require_once 'include/DB_Functions.php';
?>
And it gives me this error:
Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
Fatal error: require_once(): Failed opening required 'include/DB_Functions.php' (include_path='.:/usr/local/php-5.4.45/share/pear') in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
However, my include folder contains all the required php files. So what might be the issue here?
Try this demo code or plz share your folder structure
require_once(__DIR__.'/../include/DB_Functions.php');
I have Xampp running on Ubuntu 12.04. I have a php page in which i've included another file like include 'dbconfig.php'. But whenever I try to open the page I get an error like this:
Warning: require(1): failed to open stream: No such file or directory in /opt/lampp/htdocs/index.php on line 2
Fatal error: require(): Failed opening required '1' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/index.php on line 2
I have tried using the relative path, the full path and everything. I have also double-checked that dbconfig.php IS present in the same folder as index.php. I googled around a bit and i think the problem is that php is unable to open dbconfig.phpbecause of 'permission' issues.
I'm new to ubuntu, so I have no idea how to fix this. Can someone please help me out?
The code from index.php goes like this :
<?php
include 'dbconfig.php';
?>
All,
I have the following files:
builder.php
Oauth.php
twitteroauth.php
Within my builder.php page I have the following code:
require_once('twitteroauth.php');
Then in my twitteroauth.php page I have the following code:
require_once('OAuth.php');
All of these files are in the following path: wp-content/themes/alyeska/framework/frontend/functions
I'm testing this on my localhost and it works fine. However, when I upload all of these files to my webserver I get the following error message:
Warning: require_once(OAuth.php) [function.require-once]: failed to open stream: No such file or directory in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
Fatal error: require_once() [function.require]: Failed opening required 'OAuth.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
I'm not sure why I'm getting these errors since it works on my localhost. Can anyone point me in the right direction on how to fix this issue?
Thanks!
Two things jump to mind- make certain your path is correct, including the case sensitivity; also, make certain that the permissions on the file allow for the php server to read the file. A 644 mode should be sufficient, I believe; but, worst case, a 755 would definitely work.
And finally you may want to check whether your include path is correct.