I faced a few days ago
. 那时候我修好了,但现在它不起作用了。好吧,有些是可行的。
AjaxFileUpload Plugin
在我的wp插件中上传文件。此插件调用
uploader.php
我可以使用
$_FILES['uploadFile']
但是我无法找回
$_POST['current_path']
数据。
不过我有个理论。当我加载上载数据的接口时,隐藏的输入字段“当前路径”为空(应该为空)。当我浏览文件夹时,隐藏的输入字段将使用jquery进行更新。
上传文件
通过
$_POST
和
$_FILES
.
但是为什么我能从
$x文件
而不是来自
美元邮报
?
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);