在另一个目录(相对路径)中使用带有 php 脚本的 HTML 表单操作 [英] Using HTML form action with a php script being in another directory (relative paths)
问题描述
这是我的目录树的样子
/application
/lib
/util
/login
/views
/base_view
我的登录页面是
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
这是我的表单声明
<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
哪个是错误的路径并生成错误 404.
Which is the wrong path and generates a Error 404.
那么我在表单声明中使用相对路径的方式有什么问题,我该如何解决?
So what's wrong with the way I'm using relative paths in my form declaration and how can I fix that?
推荐答案
在你的相对路径 ./util/login/main.php
中,你正在使用 ./
指的是当前文件夹,因此它假定文件夹结构 /util/login
位于 /base_view
内.您应该尝试使用引用父文件夹的 ../
:
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:
<form class="form_login" action="../../util/login/main.php" method="POST">
...
</form>
这篇关于在另一个目录(相对路径)中使用带有 php 脚本的 HTML 表单操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!