![](/img/trans.png)
[英]How to serve a video from a file outside the web root in PHP to a html5 video source
[英]Bottle web server - how to serve PHP file?
我正在使用使用Bottle路由的其他人制作的Web应用程序。 我想创建一个需要一些PHP的简单登录页面。 如果我将PHP页面作为static_file返回,则出于显而易见的原因,将执行任何HTML,但不会执行PHP。 我应该如何提供PHP文件,使其动态化?
无法运作:
@route('/login')
def serve():
return static_file('login.php', root='.')
为了服务器PHP文件,您需要在Web服务器上安装PHP。 此外,需要将Web服务器配置为检测PHP文件并执行它们。
从Python提供PHP文件是没有用的,因此不建议这样做。 我建议您花些时间将此脚本从PHP转换为Python。
我昨天想做同样的事情,但是我对问题的回答清楚地表明,这既不可能,也非常困难。 我想到编写一个小的python程序来运行服务器内置的PHP。 注意:PHP必须能够从命令行运行,才能正常工作。
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
请记住,端口必须为4个数字。 托管此代码后,只需在浏览器中键入代码,即可从运行此代码的文件夹中返回任何文件。 例:
localhost:8080/login.php
在您要求的localhost端口上返回login.php(如果存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.