Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php函数调用直接作为html表单操作_Php_Html_Forms - Fatal编程技术网

php函数调用直接作为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

我发现下面的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" 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>


感谢分形学家的澄清。经过一段时间的调查,我发现我的代码并没有像你建议的那样起作用。谢谢你的解决方案。似乎还没有足够的声誉。对不起,是的,我没看到。所以继续提问;-)