【问题标题】:How can I call a script which is out of html directory? [closed]如何调用不在 html 目录中的脚本? [关闭]
【发布时间】:2018-02-17 11:15:47
【问题描述】:

这是我的目录结构:

/var
   /www
       myscript.php
       /html
           index.php

目前,index.php 为空。我想知道,我应该在里面写什么才能通过 http 请求调用myscript.php 脚本?

【问题讨论】:

  • myscript.php文件放入html文件夹(-;
  • @Neodan 也许他们的myscript.php 包含一些不应从公共区域访问/查看的内容,并且可能是“任何内容”。编辑:我对这个 Martin 是否正确?
  • 答:您需要做的是使用“指向”该文件的完整系统路径。
  • @Fred-ii- 那么为什么他想通过http://domain/myscript.php 之类的网址访问它? :)
  • @MartinAJ 我打算编辑我​​的原始评论以保留它,我只是没有时间。 “包含”基本上是一个“基本”示例 ;-) 可能是 include_oncerequirerequire_once,请自行选择 ;-)

标签: php url routing directory-structure


【解决方案1】:

这通常有效:

<?php // index.php : url is /html/index.php
include('../myscript.php);

如果你想做相反的事情:

<?php // myscript.php : url is /myscript.php
include('html/index.php);

【讨论】:

  • 选择myscript.php的URL应该是什么样子?
  • 他只需要上一个目录,而不是两个。
  • @kainaw 对,谢谢
  • @MartinAJ 这段代码是为了让你调用 /html/index.php,如果你想做相反的事情,我会编辑答案。
猜你喜欢
  • 2017-02-22
  • 2015-09-07
  • 2014-11-19
  • 2013-02-20
  • 2019-05-16
  • 2020-11-18
  • 1970-01-01
  • 1970-01-01
  • 2012-06-09
相关资源
最近更新 更多