php路径有关问题
php路径问题
1、如果目录结构简单,可以通过调整包含文件的层次结构来解决,仍然使用相对路径。
3、结合使用绝对路径和相对路径,有时为了赶进度可以先行让项目通过。
4、使用dirname(__FILE__)获取当前文件的目录路径,比如:
require_once(dirname(__FILE__)."../../include/cfg.php");
5、使用下面的这个语句可以把当前目录设置为当前文件的目录路径,也较为方便,尤其是交叉引用的时候非常有用。
chdir(dirname(__FILE__));
6、对于使用虚拟主机的用户可以在包含文件之前使用set_include_path()函数,比如:
set_include_path(‘./’.PATH_SEPARATOR.dirname(__FILE__));
require_once(‘include/cfg.php’);
7、通过辅助设置php配置文件中的的include_path参数进行查询路径,include_path是指将要用到的包含文件所在的目录,可以将经常include文件放到一个统一的目录里,然后把这个目录设置在配置文件php.ini的include_path参数后面,在需要使用这些包含文件的时候只需要包含其名称即可,比如就可以了,而实际上metsky_cfg.php文件则是存在设置的文件目录里。
附PHP.ini文件中include_path部分内容:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;D:\xampp\php\PEAR"
; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues. The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root
doc_root =
; The directory under which PHP opens the script using /~username used only
; if nonempty.
; http://php.net/user-dir
user_dir =
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
extension_dir = "D:\xampp\php\ext"
......
8、通过.htaccess配置文件进行路径修改也可以达到上一条类似的效果,比如
php_value include_path "./include"
ref:http://www.metsky.com/archives/323.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
