php 我如何访问父文件夹php中的文件夹或文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2929883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:10:16  来源:igfitidea点击:

how can i access a folder or file in parent folder php

phphtmlshared-directory

提问by gin

i want a shared folder which contains images to be accessed by html pages inside sub folders.(child folders)

我想要一个共享文件夹,其中包含子文件夹内的 html 页面要访问的图像。(子文件夹)

回答by Tesserex

If you mean your html folder and images folder are siblings, you're probably looking for the ..directory... um, thingy.

如果你的意思是你的 html 文件夹和图像文件夹是同级的,你可能正在寻找..目录......嗯,小东西。

Your files look like:

您的文件如下所示:

/www
    /html
        index.php
    /images
        myimage.png

Write an img tag like this:

像这样写一个 img 标签:

<img src="../images/myimage.png" />

回答by SLaks

Make a folder inside your website and put images into it.

在您的网站内创建一个文件夹并将图像放入其中。

回答by Zuul

If I got it right, you have a folder with many folders inside, and inside does many folder you have html pages, and you want does pages to access the first folder...

如果我猜对了,你有一个文件夹,里面有很多文件夹,里面有很多文件夹你有 html 页面,你想要页面访问第一个文件夹......

main_folder

主文件夹

pic.png

图片.png

pic.gif

图片.gif

pic.jpg

图片.jpg

sub_folder

子文件夹

html_page.php

just use ../pic.png when you call the image file from the html_page.php

当您从 html_page.php 调用图像文件时,只需使用 ../pic.png

Was this what you where looking for ?

这是你要找的吗?

回答by Konerak

Basically, there are two ways of linking to a resource (page/script/image/whatever):

基本上,有两种方法可以链接到资源(页面/脚本/图像/任何):

  • Use an absolute link: http://www.yourserver.com/path/to/resource.jpg
  • Use a relative link: for example, to go from http://www.yourserver.com/path/from/page.htmlto http://www.yourserver.com/path/to/resource.jpg, you use ../to/resource.jpg
  • 使用绝对链接: http://www.yourserver.com/path/to/resource.jpg
  • 使用相对链接:例如,要从http://www.yourserver.com/path/from/page.htmlhttp://www.yourserver.com/path/to/resource.jpg,您可以使用../to/resource.jpg

So just put your images on a publicly accessibly folder, and refer to them using one of those two methods.

因此,只需将您的图像放在可公开访问的文件夹中,然后使用这两种方法之一引用它们。

Or refine your question :)

或完善您的问题:)

回答by Colonel Sponsz

You can get the directory of the current file with the dirnamefunciton:

您可以使用dirname函数获取当前文件的目录

dirname(__FILE__)

If you want the parent directory you can use '..' thus:

如果你想要父目录,你可以使用 '..' 因此:

$current_dir = dirname(__FILE__);
$parent_dir = $current_dir.'/..';