AjaxFileUpload插件不检索$ _POST或$ _FILES数据 [英] AjaxFileUpload Plugin does not retrieve $_POST or $_FILES data
问题描述
好的,我希望这将成为我关于动态文件上传的一系列问题中的最后一个问题。 我使用 AjaxFileUpload Plugin ,并尝试使用我的uploader.php中的FORM数据。问题是 $ _ POST
和 $ _ FILES
都是NULL。
这是我的HTML代码:
< form id =uploadFormenctype =multipart / form-data action =method =POST>
< input type =hiddenname =MAX_FILE_SIZEvalue =1000000/>
< input type =hiddenname =current_pathvalue =<?php echo $ fb-> relative_url;?> />
< input id =uploadFilename =uploadFiletype =file/>
< input type =buttonclass =button uploadImagevalue =<?php _e('Upload File')?> /> < br />
< / form>
这是我的JS脚本:
<$ ('。'uploadImage')。live('click',function(){
ajaxFileUpload();
}){code> //文件上传
;
$ b(...)
函数ajaxFileUpload(){
jQuery.ajaxFileUpload({
url:'../ wp-content / plugins /wp-filebrowser/uploader.php',
secureuri:false,
fileElementId:'uploadFile',
dataType:'json',
成功:函数(数据,状态) {
alert('Error:'+ data.error +' - Respons:'+ data.respons)
},
error:function(data,status,e){
alert('Error:'+ e);
}
}
)
return false;
$ / code>
为了测试我的数据是否受限,我有以下的PHP代码:
$ data ['error'] = $ _POST ['current_path']; //给我NULL
$ data ['respons'] = $ _FILES ['uploadFile'] ['name']; //给我NULL
//在json
中返回结果echo json_encode($ data);
更新 $ b 佩克(用他的好眼睛)非常好的帮助后,我已经得到它的工作!
您正在分配
fileElementId:'uploadFile',
但是您的文件字段事实上并没有这个ID。
你的PHP脚本应该在
< code $ _ FILES [uploadFile] [name]
Ok, I hope this will be my last question in a series of Q's regarding dynamic file upload.
I'm using AjaxFileUpload Plugin and try to work with the FORM data in my uploader.php. The problem is that both $_POST
and $_FILES
is NULL.
This is my HTML code:
<form id="uploadForm" enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="hidden" name="current_path" value="<?php echo $fb->relative_url; ?>" />
<input id="uploadFile" name="uploadFile" type="file" />
<input type="button" class="button uploadImage" value="<?php _e('Upload File') ?>" /> <br />
</form>
And this is my JS script:
//File upload
jQuery('.uploadImage').live('click',function() {
ajaxFileUpload();
});
(...)
function ajaxFileUpload() {
jQuery.ajaxFileUpload ( {
url:'../wp-content/plugins/wp-filebrowser/uploader.php',
secureuri:false,
fileElementId:'uploadFile',
dataType: 'json',
success: function (data, status) {
alert('Error: ' + data.error + ' - Respons: ' + data.respons)
},
error: function (data, status, e) {
alert('Error: ' + e);
}
}
)
return false;
}
To test that I data is submited, I have the following PHP code:
$data['error'] = $_POST['current_path']; // Gives me NULL
$data['respons'] = $_FILES['uploadFile']['name']; // Gives me NULL
// Return result in json
echo json_encode($data);
UPDATE
After very good help from Pekka (with his good set of eyes), I have got it working! The code is updated with the correct code.
You are assigning
fileElementId:'uploadFile',
but your file field doesn't in fact have that ID.
And your PHP script should look in
$_FILES["uploadFile"]["name"]
这篇关于AjaxFileUpload插件不检索$ _POST或$ _FILES数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!