在另一个目录(相对路径)中使用带有 php 脚本的 HTML 表单操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16967526/
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
Using HTML form action with a php script being in another directory (relative paths)
提问by Flayshon
Here's what my diretory tree looks like
这是我的目录树的样子
/application
/lib
/util
/login
/views
/base_view
My login page is
我的登录页面是
localhost:737/astuto-lena/branches/application/views/base_view/index.php
And I want the action of my form to be this
我希望我的表格的动作是这样的
localhost:737/astuto-lena/branches/application/util/login/main.php
Here's my form declaration
这是我的表单声明
<form class="form_login" action="./util/login/main.php" method="POST">
...
</form>
But when I click the submit button, it takes me to
但是当我点击提交按钮时,它需要我
localhost:737/astuto-lena/branches/application/views/base_view/util/login/main.php
Which is the wrong path and generates a Error 404.
这是错误的路径并生成错误 404。
So what's wrong with the way I'm using relative paths in my form declaration and how can I fix that?
那么我在表单声明中使用相对路径的方式有什么问题,我该如何解决?
采纳答案by DarkAjax
In your relative path ./util/login/main.php
, you're using ./
which refers to the current folder, so it assumes that the folder structure /util/login
is inside /base_view
. You should try using ../
which refers to the parent folder:
在您的相对路径中./util/login/main.php
,您正在使用./
which 指的是当前文件夹,因此它假定文件夹结构/util/login
在/base_view
. 您应该尝试使用../
which 引用父文件夹:
<form class="form_login" action="../../util/login/main.php" method="POST">
...
</form>
回答by Half Crazed
You need to set the action to a better relative path or use an absolute path. Examples:
您需要将操作设置为更好的相对路径或使用绝对路径。例子:
../../util/login/main.php
or
或者
/astuto-lena/branches/application/util/login/main.php
./
simply means this directory
(aka current working directory
)
./
只是意味着this directory
(又名current working directory
)
回答by Luferquisa
You must use .. / to go to parent directory
您必须使用 .. / 转到父目录
<form class="form_login" action="../../util/login/main.php" method="POST">
...
</form>
回答by Divyang Vashi
I faced the a similar problem and the error I got was object not found
/application
/includes
connect.php
insert.php
index.php
我遇到了类似的问题,我得到的错误是找不到对象
/application
/includes
connect.php
insert.php
index.php
<form action="/includes/insert.php" method="post">
//code
</form>
the above code didn't work and showed the error 404, Object Not Found. But,
上面的代码不起作用并显示错误 404,找不到对象。但,
<form action="./includes/insert.php" method="post">
//code
</form>
The only difference is adding .
in the action path.
The strange things is /include/filename
works fine for require
or include
but you will need to add .
for form action attribute
唯一的区别是添加.
操作路径。奇怪的事情/include/filename
适用于require
或include
但您需要添加.
表单操作属性