大佬教程收集整理的这篇文章主要介绍了我如何将 php 变量传递给 python 脚本,以便 python 将在浏览器(xampp)中显示传递变量,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 HTML 文件 <input type='file' name='loadfile'>
我想做一些事情,比如在加载文件时获取文件名 $nameOfThefile = $_fileS["loadfile"]["name"];
,然后将 fil@R_874_8371@
传递给名为 ({{1} }) 并使用python文件读取formatfiletoJsON.py
并将其格式化为JsON格式。并使用 fil@R_874_8371@
在浏览器中打印出 Json 格式,以便我的 AJAX 文件可以得到 (Json.dumps()
)
问题:在我的 formatfiletoJsON.py
中无法在浏览器中获取文件名变量(formatfiletoJsON.py
),它是空的
xampp localhost
print(sys.argv)
fil@R_874_8371@ = sys.argv[1]
print(fileName)
我做了什么:
file "c:\xampp\htdocs\project_real\receivephpvariable.py",line 5,in <module>
fil@R_874_8371@ = sys.argv[1]
IndexError: List index out of range
formatfiletoJsON.py
<?php
if (isset($_fileS["loadfile"]) > 0)
{
$nameOfThefile = $_fileS["loadfile"]["name"];
$temp = sHell_exec("python formatfiletoJsON.py \"$nameOfThefile\"");
echo $temp;
}
//HTML
<form action="<?php HTMLentitIEs($_SERVER['php_SELF'])?>" method="post" enctype="multipart/form-data">
SELEct image to upload:
<input type="file" name="loadfile" ID="loadfile">
<input type="submit" value="Upload Image" name="submit">
</form>
我想传递给php的文件名(function.py)
#!C:\Python\python39\python.exe
import Json
import sys
print ('Content-type: text/HTML\n\n')
fil@R_874_8371@ = sys.argv[1]
with open(fil@R_874_8371@ +'.py','r') as infile:
funcs = infile.read().split('\n\n')
# print(funcs)
result = {}
for elem in funcs:
if elem.startswith('def'):
sign,commands = elem.split(':')
# print(List(map(str.Strip,commands.split('\n')))[1:])
commands = List(map(str.Strip,commands.split('\n')))[1:]
result.update({sign : commands})
# print(result)
y = Json.dumps(result)
print(y)
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的我如何将 php 变量传递给 python 脚本,以便 python 将在浏览器(xampp)中显示传递变量全部内容,希望文章能够帮你解决我如何将 php 变量传递给 python 脚本,以便 python 将在浏览器(xampp)中显示传递变量所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。