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.
Related
During the execution of a project in PHP ( CodeIgniter ) I get this error.
It corresponds to that line of code in the file Session_files_driver.php of CodeIgniter.
Previously I worked on Linux, but since I passed under W10, I get this error.
Thanks for your help.
A PHP Error was encountered
Severity: Warning
Message: touch(): Unable to create file
sys_get_temp_dir()\ci_sessionc1e70147453a4c2aa17523a19927bce80ef4afe9
because No such file or directory
Filename: drivers/Session_files_driver.php
Line Number: 234
Backtrace:
if (($this->_file_handle = fopen($this->_file_path.$session_id, 'w+b')) === FALSE)
It appears that you've provided 'sys_get_temp_dir()' as a string (note the quotes) for your sess_save_path value. It's a function, you're not supposed to put quotes around it.
Also, it's a bad idea to use the system-wide temporary directory for your session files' location. That directory is readable by everybody, which means that any other user on the system can read your users' session data - you must avoid that!
Most likely a write permission error. Grant apache user the permission to write to disk.
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
I am new to moodle. I am trying to query the moodle database using my own PHP scripts. I am using the data manipulation API but i can't seem to fetch anything. What are the steps i should take to accomplish this. I have seen a number of guidelines here and there that I should include the config.php file in moodle so as to access the $DB global variable and hence access the functions of the DML API. The following is my code:
<?php
require '../config.php';
global $DB;
$user= $DB->get_record_sql('SELECT * FROM {mdl_user} WHERE id=?', array(4));
echo mysql_num_rows($user);
?>
I get the following error when I try to run it on TextMate editor:
PHP Warning: Â require(../config.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
PHP Fatal error: Â require(): Failed opening required '../config.php' (include_path='.:') in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
I will appreciate the help...Thanks.
This error:
PHP Warning: require(../config.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
means that the script can't find a file called config.php. ../config.php means the script is going to try and open a file in the script's parent directory called config.php. Be sure your script is actually in that location. If it is not, I recommend changing ../config.php to ./config.php and moving your script into the same directory as config.php.
Because your script can't find config.php, it can't connect to the database (config.php should store the credentials, URL, ect.)
I think you are giving wrong path. please be sure that the path you are giving is correct like
require_once('path_from_rootdir to config.php');
note: path_from_rootdir to config.php is the path to config.php and each directory between the path separated by '/'.
There are two issues with this (as wriiten in the question) four lines code of Moodle-
require '../config.php';
Here code is getting error- "PHP Warning: require(../config.php): failed to open stream" because config.php is being looked into the parent directory & file is not there. Please check the path & put the correct path of config.php.
$user= $DB->get_record_sql('SELECT * FROM {mdl_user} WHERE id=?', array(4));
While working with Moodle DML API, table prefix(by default mdl_) must not be added before the table name within {}. Thus, there must be only {user} in place of {mdl_user}.
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.
I have a PHP script which reads from an xml file to generate a table. The first thing it does is check to make sure the file exists.
$path = getcwd();
if(file_exists($path.'\inc\php\kbs.xml')){
$kbs = simplexml_load_file($path.'\inc\php\kbs.xml');
} else {
echo "Error: No KB file found";
}
For some reason, intermittently, it doesn't find the file. I've tried removing the file_exists check all together (since I know the file does exist) but it still doesn't load the file at times. I can refresh the page and 7 times out of 10 it doesn't load, but sometimes it does.
I never ran into this problem during development, but once it went production (being used by maybe 200 users now) it started happening.
How do I go about troubleshooting this? (PHP 5.2.14 running on IIS)
EDIT: Error logs give me the following messages when it fails:
Notice: Undefined variable: kbs in <the path> on line 16
Notice: Trying to get property of non-object in <the path> on line 16
Warning: Invalid argument supplied for foreach() in <the path> on line 16
line 16 is the first time the variable $kbs is accessed. Obviously $kbs isn't set if the file isn't found.
Please use the absolute path, relative path make things a mess.
Is the location relative to PHP? Do permissions allow the web server to see it?