我在上传任何文件时遇到问题。我的单词新闻网站正在使用Ajax Page Loader插件。当表单提交时,页面不会刷新..
我在 print_r($ _ FILES);
中的functions.php中的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>
j查询
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]);
}
}
}