This question already has answers here:
PHP include file. Showing error file not found
(3 answers)
Php include not working? function not being included
(6 answers)
PHP include not loading file
(1 answer)
Closed 3 days ago.
My php Web app is not reading files correctly on azure. How do I fix this ? The web app correctly works in my computer.
The file directory
mainFolder->common_files (common files have all the files used by all the web pages)
mainFolder->pages (pages will have all the .php files except index.php)
mainFolder-> index.php
The index.php files works correctly. However, the .php files inside the "pages" folder does not go to the common_files folder.
I used the following code to include those files from common_files folder:
(The .php files inside "pages" folder use this code)
<head>
<?php require('../common_files/headfiles.php') ?>
</head>
The webpage should load files from o:
https://glidingcub.azurewebsites.net/common_files/
But try to load from:
https://glidingcub.azurewebsites.net/pages/common_files/
How do I fix this ?
Related
This question already has answers here:
How to get the home directory from a PHP CLI script?
(13 answers)
Closed 2 years ago.
I am trying to get content from file at home directory and want to avoid absolute path using tilde in path
I have created file in shell
echo "test" > ~/test_file.txt
Then I am trying to read the file with PHP file_get_contents()
file_get_contents('~/test_file.txt')
Getting following PHP error
Warning Error: file_get_contents(~/test_file.txt): failed to open stream: No such file or directory
Update
This is duplicate of https://stackoverflow.com/a/1894954/2686510
Code snippet I use now
$home = getenv("HOME");
file_get_contents($home . DIRECTORY_SEPARATOR . 'test_file.txt');
Answer for your question is here https://stackoverflow.com/a/1894954/2686510
In short, use $_SERVER['HOME'] variable to access current user home folder.
This question already has answers here:
PHP display current server path
(5 answers)
PHP absolute path to root
(8 answers)
How do you know the correct path to use in a PHP require_once() statement
(9 answers)
Closed 3 years ago.
I am absolutely terrible with using 'require', 'include' and 'require_once' to locate my files and include them inside other .php files and would like some assistance.
The class where it's located:
htdocs (Main)
- wp-content
-- mu-plugins
--- extensions
---- _process
----- pp
------ classes
------- Control.php (Class)
Now I need to require_once the class 'Control.php' in the following structure:
htdocs (Main)
- wp-content
-- mu-plugins
--- extensions
---- _process
----- oc
------ run.php (Need to call inside this file)
How would I be able to achieve this? I've tried everything and can't figure out how to call files and structures.
I've tried this and it didn't work inside run.php:
require_once (__DIR__.'/../pp/classes/Control.php');
Personally, when I have to make the include or require of the case, I create a constant and use the global variable SERVER.
Example.
define( "PATH", $_SERVER['DOCUMENT_ROOT']);
require PATH . "/wp-content/mu-plugins/extensions/_process/pp/classes/Control.php"
In this way, using the SERVER variable, your path will always start from the main root of the site.
I hope it helps you.
Having said that, being in Wordpress, why don't you use the wp-load.php file?
By including that file in your project, you automatically have everything that is part of wordpress available to you. Think about it, it might come in handy later in the other files.
Enjoy :)
This question already has answers here:
Get relative path to a parent directory
(2 answers)
Closed 8 years ago.
So I have this sort of file set up. /cloud/ and /embed/ being two different subdomains.
www
-cloud
--config.php
--files
---formSubmit.php
-embed
--index.php
in /embed/index.php I have the following code:
include("/www/cloud/files/formSubmit.php");
in /cloud/files/formSubmit.php I have the following code:
include("../config.php");
If I am on cloud.website.com and I go to the formSubmit.php, everything works fine and the config file is included.
However, If I am on embed.website.com and I go to the index.php, I get an error saying that config.php was not found.
Does anyone know what do I need to do to include my formSubmit.php from either location and have my config.php included?
In this case, it seems your usage of relative paths is working and absolute paths are not. Whether that means the absolute path of /www/cloud/files/ is incorrect or not, I do not know. In my code, I tend to try to reference files relatively as much as possible like so:
// In embed/index.php
include_once dirname(dirname(__FILE__)) . '/cloud/files/formSubmit.php';
What that does is get the directory of the currently executing file and then it's parent directory, which would be www, and then goes back down the path from there to the file I need.
Subdomains should not make a difference when accessing files server side (as long as the files are hosted on the same server).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Wordpress root directory
I need to write a file in the root directory on a wordpress installation. This need to be in the same place as the wp-config.php file.
But i need a way to call the root url.
Is there a wp_root_dir() like function
Do you want root url or root dir?
Given that you're putting this file into the root of your wordpress I assume its not a plugin or something like that.
Here is how to get the root url
<?php echo get_bloginfo('url'); ?>
Otherwise if you want the path (to include() for instance) its perfectly reasonable to just do:
../../../file-in-root.php -> as many ../s as you need to go back directories
I do this all the time. If you think your directory structure may change a lot, you can just put the whole path to the file e.g.
/home/w/o/wordpress/web/public_html/file-in-root.php
If you're creating a plugin and you don't know the path to the file then obviously it would be different, but there are wordpress functions for that. However as you're using root I guess this is just for your own server/website configuration and this will be fine.
If you mean on the client side (http://www.myreallyawesomewebsitethatuseseordpress.com/blog/wordpress/), you can use get_bloginfo('url'). This will return the url which wordpress is installed.
If you mean on the server side, you can use the ABSPATH variable.
Usage:
Client side:
<?php
echo "You are using this site. Wordpress is on" . get_bloginfo('url');
?>
Server side:
<?php
echo "On the server, Wordpress is installed on" . ABSPATH;
?>
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
APACHE, prevent users from accessing include files?
How do I prevent public access to php include files?
Let's say that I have a header.php, footer.php, a folder with multiple include files and I don't want users to access them directly by typing the filenames in the address bar. What is the best way to prevent this?
Thank you for your help
Move them outside of the web root.
Eg my web root is htdocs
.
├── htdocs
└── php
And php is outside of it
I include files like this
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/../php/prepend.php");
include($_SERVER["DOCUMENT_ROOT"] . "/../php/common.inc");