這與I faced a few days ago幾乎完全相同。我修好了,但現在不再工作了。那麼,它的一些作品。
我使用AjaxFileUpload Plugin上傳我的WP插件中的文件。這個插件調用uploader.php
來處理上傳表單。
我能夠使用$_FILES['uploadFile']
獲得文件名(和其他數據),但我無法檢索$_POST['current_path']
數據。
雖然我有一個理論。當我加載接口上傳數據時,隱藏的輸入字段'current_path'是空的(應該是這樣)。在瀏覽我的文件夾時,使用jQuery更新隱藏的輸入字段。
當我點擊上傳按鈕時,Ajax File Upload插件將上傳表單中的數據取出,並將數據傳遞到uploader.php
到$_POST
和$_FILES
。
但爲什麼我能從$_FILES
而不是從$_POST
獲取數據?
這裏是我的代碼:
的Javascript
//File upload functions
// Remove feedback message on upload click
jQuery('.uploadImage').live('click',function() {
ajaxFileUpload();
});
(...)
//Lets upload the file by using Ajax uploader plugin
function ajaxFileUpload() {
alert(jQuery('input[type=hidden][name=current_path]').val()) //Shows me the correct current path
jQuery.ajaxFileUpload ({
url:'../wp-content/plugins/wp-filebrowser/uploader.php',
secureuri:false,
fileElementId:'uploadFile',
dataType: 'json',
success: function (data) {
if(data.error != '') {
alert(data.error);
} else {
alert(data.respons);
}
},
error: function (e) {
jQuery('#uploadOutput').addClass('error').html('Error: ' + e).show();
},
complete: function() {
// Update file list
}
}
)
return false;
}
HTML
<form id="uploadForm" enctype="multipart/form-data" action="" method="POST">
<input type="hidden" id="current_path" 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>
PHP
$this->current_path = $_POST['current_path'];
$this->data['error'] = $_FILES['uploadFile']['name']; //Just for testing
$this->data['respons'] = "Filename: ".$_POST['current_path'];
echo json_encode($this->data);
狗屎。你是對的。我還沒有成功使用jQuery表單插件,但會給它另一個鏡頭。 – Steven 2010-09-13 11:23:50