2012-01-23 22 views
1

我需要知道它從POST字典中正確獲取filedata。

我想在我的項目中使用Agile Uploader(在上傳到服務器之前在客戶端調整圖像大小)。它具有process.php文件作爲在服務器上處理圖像的示例。在該文件中:

$tmp_name = $_FILES["Filedata"]["file_name"];  // where "tmp_name" is file name 

金字塔有沒有FILES字典,我supose我必須找到圖像中POST。但是,當我嘗試上傳圖像POST是空的...

那麼它發送該圖像以及如何在服務器端找到它?

HTML(從他們demo採取的HTML代碼大部分):

<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

發佈您的html和python代碼。 – soulcheck

+0

@soulcheck - 添加了html和python代碼 –

回答

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關於文件上傳。