douyue7536
douyue7536
2011-04-28 20:16

如何访问php中另一个文件夹中的文件

已采纳

I need to include a php file to one of my file.

I have a php file like www.example.com/free/index.php.

I need to include another php file from this directory www.example.com/downloads/apple_count.php

I wrote this code inside that index.php page

<?php
include('..\downloads/apple_count.php');
?>

But it's not working. :( It says Warning: include(..\downloads/apple_count.php) [function.include]: failed to open stream: No such file or directory.....

Please help me to do this :(

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dselp3944 dselp3944 10年前

    php on windows or linux?

    if you are constantly including out of the same file you could use

    set_include_path('/absolute/path/to/folder/');
    

    either way you need to flip that ..\ into a ../

    点赞 评论 复制链接分享
  • doulun1666 doulun1666 10年前

    The path you specific is relative to the current work direcotry, not the directory from where you call it, and its not resolved against the include path. Try absolute pathes

    include(dirname(__FILE__) . '/../downloads/apple_count.php');
    

    Paths starting with / are absolute, starting with . oder .. are relative against the current work directory and everything else is resolved against the include-path.

    点赞 评论 复制链接分享
  • doutian4046 doutian4046 10年前

    Are you using rewriting? Did you try include('/downloads/apple_count.php');

    点赞 评论 复制链接分享
  • doulan8152 doulan8152 8年前

    set_include_path('/absolute/path/to/folder/');

    点赞 评论 复制链接分享