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
but your file field doesn't in fact have that ID.
And your PHP script should look in