我需要知道从POST词典中正确获取filedata。
我想在我的项目中使用Agile Uploader(在服务器上传之前在客户端调整图像大小)。它有process.php文件作为在服务器上处理图像的示例。在该文件中:
$tmp_name = $_FILES["Filedata"]["file_name"]; // where "tmp_name" is file name
由于金字塔没有FILES
字典,所以我必须在POST
找到图片。但是当我尝试上传图片时,POST
是空的......
那么它在哪里发送该图像以及如何在服务器端找到它?
HTML(大部分html代码来自他们的demo):
<form action="/test" method="post" id="singularDemo" enctype="multipart/form-data">
<div id="single"></div>
</form>
<a href="#" onClick="document.getElementById('agileUploaderSWF').submit();">Submit</a>
<script type="text/javascript">
$('#single').agileUploaderSingle({
submitRedirect:'',
formId:'singularDemo',
progressBarColor:'#3b5998',
flashVars:{
firebug:true,
form_action:'/test'
}
});
</script>
Python(金字塔代码),仅用于测试 - 简单视图:
def test(request):
if request.method == 'POST':
pass
return {}
谢谢!
答案 0 :(得分:4)
由于$_FILES
全局包含POST
请求提交的文件,您可以使用request.POST
访问它们:
# access the filename
filename = request.POST['Filedata'].filename
# access the actual file
input_file = request.POST['Filedata'].file
这与PHP $_FILES
变量完全等效,因此如果它不起作用,其他一些必须是错误的。
金字塔食谱有关于文件上传的more information。