我在上传任何文件时遇到问题。我的 word press 网站正在使用Ajax Page Loader Plugin.So 表单提交时页面没有刷新..
我在print_r($_FILES);PHP
中的 functions.php 中的代码没有任何价值;
但是当我打印任何字符串时,echo();
它正在打印,但为什么print_r($_FILES); 没有得到任何价值。
HTML 表单
<form id="career_form" name="career_form" enctype="multipart/form-data">
<span id='errfrmMsg' style='margin:0 auto;'></span>
Upload : <input id="career_resume" class="field" style="height: 25px;" type="file" name="career_resume" multiple /></td>
<input type="hidden" name="action" value="career" />
<input id="submit_button" onclick="submit_career();" type="button" value="Send" />
</form>
查询
function submit_career()
{
jQuery.post(the_ajax_career.ajaxurl_career,
jQuery("#career_form").serialize(),
function(response_from_the_action_function){
jQuery("#errfrmMsg").html(response_from_the_action_function).css({"display":"block"});
}
);
}
functions.php 中的 PHP 代码
wp_register_script("ajax-career", get_bloginfo('template_directory')."/js/custom_js.js", array( "jquery"));
wp_enqueue_script('ajax-career');
wp_localize_script("ajax-career","the_ajax_career", array("ajaxurl_career" => admin_url("admin-ajax.php")));
// add actions
add_action( "wp_ajax_career", "ajax_action_career" );
add_action( "wp_ajax_nopriv_career", "ajax_action_career" );
function ajax_action_career(){
//Nothing getting in this print_r($_FILES) function;
foreach ($_FILES["career_resume"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$name = $_FILES["career_resume"]["name"][$key];
move_uploaded_file( $_FILES["career_resume"]["tmp_name"][$key], "uploads/" . $_FILES['career_resume']['name'][$key]);
}
}
}