php函数调用直接作为html表单操作
我发现下面的HTML表单代码php函数调用直接作为html表单操作,php,html,forms,Php,Html,Forms,我发现下面的HTML表单代码 <form action="<?php foo(bar)?>" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" va
<form action="<?php foo(bar)?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="submit">
</form>
PHP函数将不会作为HTML表单操作调用 实际上,在服务器将表单发送到浏览器之前,PHP函数将执行,因此表单的操作将是foo函数打印的值(如果执行了)
只要打开从服务器收到的网页源代码,就不会再看到PHP代码了。这行不通。服务器在将HTML发送到浏览器之前正在执行PHP 但这里有一个想法:
<?php
function foo($bar)
{
echo $bar;
}
if (isset($_POST['func'])){
foo($_POST['file']);
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="hidden" name="func" id="file" value="foo">
<input type="submit" name="submit" value="submit">
</form>
感谢分形学家的澄清。经过一段时间的调查,我发现我的代码并没有像你建议的那样起作用。谢谢你的解决方案。似乎还没有足够的声誉。对不起,是的,我没看到。所以继续提问;-)