金字塔:php的$ _FILES ['Filedata'] ['file_name']的类比是什么?

时间:2012-01-23 13:57:24

标签: python pyramid

我需要知道从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 {}

谢谢!

1 个答案:

答案 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