使用php include函数时出错

使用php include函数时出错

问题描述:

I'm working on a php web application under windows. I have many script files placed in their respective folders and all the files needs a file named 'connexion.php' that is situated in the root project.

The structure of the project is as follow: Projet_beta :

  -client (folder):
          *addClient.php
          *modifyClient.php
          *deleteClient.php

  - connexion.php

So, when i use include ('../connexion.php') inside the 'addClient.php' it displays this error message :

Warning: include(connexion.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\project_beta\client\addClient.php on line 3.

How can i fix this problem ? Thank's every one.

我正在使用windows下的php web应用程序。 我有许多脚本文件放在各自的文件夹中,所有文件都需要一个名为'connexion.php'的文件,该文件位于根项目中。 p>

项目结构如下: Projet_beta: p>

  -client(folder):
 * addClient.php \  n * modifyClient.php 
 * deleteClient.php 
 
  -  connexion.php 
  code>  pre> 
 
 

因此,当我使用 include('../ “addClient.php”中的connexion.php') code>会显示以下错误消息: p>

警告:include(connexion.php)[function.include ]:无法打开流:第3行的C:\ wamp \ www \ project_beta \ client \ addClient.php中没有此类文件或目录。 p> blockquote>

如何才能 我解决了这个问题? 感谢每一个人。 p> div>

Check in your httpd.conf file :

  1. left click on wamp
  2. php menu
  3. open the httpd.conf file
  4. Find the line starting with DocumentRoot
  5. Change the line to DocumentRoot "c:/wamp/www/" and save the file
  6. Restart wamp services

Then use :

include($_SERVER['DOCUMENT_ROOT'] . '/project_beta/connexion.php');

Try this include ('/../connexion.php')

The extra slash should solve your issue.

Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled.

You can use dirname func :

include(dirname(__FILE__)."/connexion.php"));

Should use

dirname(__FILE__)."../connexion.php"

instead. In this case, "../" search files from the path you executing the file, not the real path of the file.