AjaxUpload $_FILES array is empty
I'm trying to use wordpress' built-in ajax to process an upload using the AjaxUpload script. The script was updated in august, and now i can't get it to work any more.
http://valums.com/ajax-upload/
here's my jquery... this seems to be in place as i get input is transformed into an upload button and on selection of the image it begins to attempt to upload automatically.
jQuery.noConflict();
jQuery(document).ready(function($) {
/*
* AJA开发者_运维百科X UPLOAD
* http://valums.com/ajax-upload/
*/
var uploader = new qq.FileUploader({
// pass the dom node (ex. $(selector)[0] for jQuery users)
element: document.getElementById('file-uploader'),
// path to server-side upload script
action: ajaxurl,
params: {
type: "POST",
action: 'save_function',
key: 'logo',
},
onComplete: function(id, fileName, responseJSON){
console.debug("Here is the response: %o", responseJSON);
}
});
}); //end document.ready functions
my action is set to ajaxurl which is the constant for /wp-admin/admin-ajax.php, i passed an action in the params so that admin-ajax would know what function i wanted to run to process things. and my callback function
function childtheme_data_save_callback() {
global $my_shortname;
$id = $_POST['key']; // option name
$upload = wp_handle_upload($_FILES['qqfile']['tmp_name'], array('test_form' => false));
if(!empty($upload['error'])) { //there IS an error message
die($upload['error']);
}
else { // there is NOT an error
$upload_image = $my_data; //preserve current data
$upload_image[$id] = $upload['url'];
update_option($my_shortname .'_options', $upload_image ) ;
die($upload['url']); //response sends url back to jquery
}
}
add_action('wp_ajax_save_function', 'childtheme_data_save_callback');
which is getting called and my error message is showing in my firebug console. here is the error
File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.
dabbling w/ changing the error messasge to $_FILES it always comes back an empty array, even though in console it says the POST is filled w/ stuff that looks like
ÿØÿà�JFIF��_�_��ÿÛ�C� $.' ",#(7),01444'9=82<.342ÿÛ�C 2!!22222222222222222222222222222222222222222222222222ÿÀ�°
and more. though now i see that console also says the Response Headers have a content type of: Content-Type text/html; charset=UTF-8
and the request headers accept: Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
is the problem then in not sending the POST in "multipart/form-data" encoding? if so how do i switch to that since i'm using this plugin and not a form tag? if not, well i have been stumped for a while now.
You need to check the GET variable qqfile, and if it is set, it contains your file name, while the file is in the post data. The js package you got most likely contains examples/samples in various server side scripts. Also note that if the GET qqfile variable is not set you should fall back to loading with FILE[] for older browser support.
精彩评论