require-once

How does include path resolution work in require_once?

走远了吗. 提交于 2019-12-03 01:48:37
I was writing an web app in PHP, when I encountered a strange situation. To illustrate my problem, consider a web app of this structure: / index.php f1/ f1.php f2/ f2.php Contents of these files: index.php: <?php require_once("f1/f1.php"); ?> f1.php: <?php require_once("../f2/f2.php"); ?> f2.php: blank now when I try to open index.php in my browser I get this error: Warning: require_once(../f2/f2.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/reqtest/f1/f1.php on line 2 Fatal error: require_once() [function.require]: Failed opening required '../f2/f2

How to require_once from different directories?

ε祈祈猫儿з 提交于 2019-12-02 00:33:00
问题 I am trying to require my "library" files from php files in different folders, but it gives errors when trying to access them from a subfolder. For example I have such a directory: + home - file1.php ++ subfolder - file2.php ++ libraries - code_generator.php - database_library.php code_generator.php also depends on the other library: (LINE 25) require_once(realpath("./libraries/database_library.php")); //this works fine when called from file1.php, but not from file2.php I try to call code

How to require_once from different directories?

这一生的挚爱 提交于 2019-12-01 20:51:14
I am trying to require my "library" files from php files in different folders, but it gives errors when trying to access them from a subfolder. For example I have such a directory: + home - file1.php ++ subfolder - file2.php ++ libraries - code_generator.php - database_library.php code_generator.php also depends on the other library: (LINE 25) require_once(realpath("./libraries/database_library.php")); //this works fine when called from file1.php, but not from file2.php I try to call code_generator from ./subfolder/ file2.php like: chmod("../libraries/codegenerator.php", 0777); // for the

ZF Include path

折月煮酒 提交于 2019-12-01 12:51:54
Is it correct to require_once? where and how would you put it include path? Should it not be in a application.ini or bootstrap? EXAMPLE: require_once 'Zend/View/Helper/Abstract.php'; // @question - is this correct - where and // how would you put it include path class Zend_View_Helper_Translate extends Zend_View_Helper_Abstract { } David Weinraub Generally speaking, you can avoid require_once calls almost entirely by appropriately using Zend_Loader_Autoloader . Of course, the key is "appropriate". Typically, your public/index.php sets the include_path to be the library folder. Then, if you are

ZF Include path

≯℡__Kan透↙ 提交于 2019-12-01 11:21:31
问题 Is it correct to require_once? where and how would you put it include path? Should it not be in a application.ini or bootstrap? EXAMPLE: require_once 'Zend/View/Helper/Abstract.php'; // @question - is this correct - where and // how would you put it include path class Zend_View_Helper_Translate extends Zend_View_Helper_Abstract { } 回答1: Generally speaking, you can avoid require_once calls almost entirely by appropriately using Zend_Loader_Autoloader . Of course, the key is "appropriate".

How to know if php script is called via require_once()?

流过昼夜 提交于 2019-12-01 00:26:31
My webapp has a buch of modules. Each module has a 'main' php script which loads submodules based on a query sent to the main module: //file: clientes.php //check for valid user... //import CSS and JS... switch( $_GET["action"] ) { case "lista" : require_once("clientes.lista.php"); break; case "listaDeudores" : require_once("clientes.listaDeudores.php"); break; case "nuevo" : require_once("clientes.nuevo.php"); break; case "detalles" : require_once("clientes.detalles.php"); break; case "editar" : require_once("clientes.editar.php"); break; default : echo "<h1>Error</h1><p>El sitio ha

What is the scope of require_once in PHP?

喜夏-厌秋 提交于 2019-11-30 22:41:24
问题 Simple question: Is the scope of require_once global? For example: <?PHP require_once('baz.php'); // do some stuff foo ($bar); function foo($bar) { require_once('baz.php'); // do different stuff } ?> When foo is called, does it re-parse baz.php? Or does it rely on the already required file from the main php file (analagous to calling require_once twice consecutively for the same include file)? I saw this thread before, but it didn't quite answer the question: Should require_once "some file

How can I tune the PHP realpath cache?

大城市里の小女人 提交于 2019-11-30 07:32:16
Recent versions of PHP have a cache of filenames for knowing the real path of files, and require_once() and include_once() can take advantage of it. There's a value you can set in your php.ini to set the size of the cache, but I have no idea how to tell what the size should be. The default value is 16k, but I see no way of telling how much of that cache we're using. The docs are vague: Determines the size of the realpath cache to be used by PHP. This value should be increased on systems where PHP opens many files, to reflect the quantity of the file operations performed. Yes, I can jack up the

Using require_once for up directory not working

孤街浪徒 提交于 2019-11-30 06:13:06
I am using require_once like this require_once('../mycode.php') I am developing a wordpress plugin. My plugin folder is yves-slider where I have a file called yves-slider.php and a folder called admin. Inside admin folder I have a file called admin.php. I want to require file yves-slider.php in my admin.php which is located up one level directory. When I try to use require_once('../yves-slider.php') it gives me the following error Warning: require_once(../yves-slider.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\plugins\yves-slider\yves-slider

PHP Require and Include GET

半世苍凉 提交于 2019-11-30 05:40:52
问题 I would like to require a file but also pass GET variables through the url, but when I write: <?php require_once("myfile.php?name=savagewood"); ?> I get a fatal error. How would I accomplish this functionality in a different way, such that I don't get a fatal error? 回答1: variables will be available as normal you do not have to pass like this. $name='savagewood'; require_once("myfile.php"); $name will be available in myfile.php 回答2: <?php $getVarsArray = $_GET; $postVarsArray = $_POST; /* n