I have found that following HTML form code
我发现以下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>
works fine when foo(bar)
is a function available in the current scope.
当foo(bar)是当前作用域中可用的函数时,它可以正常工作。
I am very new to php and html and couldn't find any documentation of this functionality online. Are there any downsides of using <?php foo(bar)?>
instead of calling a script file foo.php
?
我是php和html的新手,在网上找不到这个功能的任何文档。使用 而不是调用脚本文件foo.php有什么缺点吗?
2 个解决方案
#1
1
The PHP function will not be called as a HTML form action.
PHP函数不会被称为HTML表单操作。
Actually the PHP function will be executed before the server send the form to your browser, so the form's action will be the value printed by the foo function if it did.
实际上PHP函数将在服务器将表单发送到您的浏览器之前执行,因此表单的操作将是foo函数打印的值(如果有的话)。
Just open the web page's sources received from your server, you shouldn't see anymore PHP code.
只需打开从服务器收到的网页源,您就不应再看到PHP代码了。
#2
0
This wouldn't work. The server is executing PHP before sending HTML to the browser.
这不行。在将HTML发送到浏览器之前,服务器正在执行PHP。
But here's an idea:
但这是一个想法:
<?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>
But IMO a better way would be to use CURL or other url-catching-and-pointing-to-controller systems, like e.g. with a Framework
但IMO更好的方法是使用CURL或其他url-catch-and-pointing-to-controller系统,例如与框架
#1
1
The PHP function will not be called as a HTML form action.
PHP函数不会被称为HTML表单操作。
Actually the PHP function will be executed before the server send the form to your browser, so the form's action will be the value printed by the foo function if it did.
实际上PHP函数将在服务器将表单发送到您的浏览器之前执行,因此表单的操作将是foo函数打印的值(如果有的话)。
Just open the web page's sources received from your server, you shouldn't see anymore PHP code.
只需打开从服务器收到的网页源,您就不应再看到PHP代码了。
#2
0
This wouldn't work. The server is executing PHP before sending HTML to the browser.
这不行。在将HTML发送到浏览器之前,服务器正在执行PHP。
But here's an idea:
但这是一个想法:
<?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>
But IMO a better way would be to use CURL or other url-catching-and-pointing-to-controller systems, like e.g. with a Framework
但IMO更好的方法是使用CURL或其他url-catch-and-pointing-to-controller系统,例如与框架