function mf_ajax_call() { $call = new mf_ajax_call(); $call->resolve($_POST); }
public function upload_ajax($data) { global $mf_domain; // pr($data); // pr($_FILES); // $resp = array('ok' => true,$_FILES,$data); // echo json_encode($resp); if (!current_user_can('upload_files')) { $resp = array('success' => false, 'msg' => __('You do not have sufficient permissions to upload images.', $mf_domain)); echo json_encode($resp); die; } if (isset($_POST['fileName'])) { $resp = array('success' => false, 'msg' => __("Upload Unsuccessful", $mf_domain)); if (isset($_FILES['file']) && !empty($_FILES['file']['tmp_name'])) { if ($_FILES['file']['error'] == UPLOAD_ERR_OK) { if (mf_ajax_call::valid_mime($_FILES['file']['type'], 'image')) { // if ( !wp_verify_nonce($_POST['checking'],'nonce_upload_file') ){ // $resp['msg'] = __('Sorry, your nonce did not verify.',$mf_domain); // }else{ $special_chars = array(' ', '`', '"', '\'', '\\', '/', " ", "#", "\$", "%", "^", "&", "*", "!", "~", "‘", "\"", "’", "'", "=", "?", "/", "[", "]", "(", ")", "|", "<", ">", ";", "\\", ",", "+", "-"); $filename = str_replace($special_chars, '', $_FILES['file']['name']); $filename = time() . $filename; @move_uploaded_file($_FILES['file']['tmp_name'], MF_FILES_DIR . $filename); @chmod(MF_FILES_DIR . $filename, 0644); $info = pathinfo(MF_FILES_DIR . $filename); $thumb = aux_image($filename, "w=150&h=120&zc=1", 'image_alt'); $resp = array('success' => true, 'name' => $filename, 'ext' => $info['extension'], 'thumb' => $thumb, 'file_path' => MF_FILES_DIR . $filename, 'file_url' => MF_FILES_URL . $filename, 'encode_file_url' => urlencode(MF_FILES_URL . $filename), 'msg' => __("Successful upload", $mf_domain)); // } } else { $resp['msg'] = __("Failed to upload the file!", $mf_domain); } } elseif ($_FILES['file']['error'] == UPLOAD_ERR_INI_SIZE) { $resp['msg'] = __('The uploaded file exceeds the maximum upload limit!', $mf_domain); } else { $resp['msg'] = __("Upload Unsuccessful", $mf_domain); } } } echo json_encode($resp); }