我从另一个主页获得此代码,并尝试在我的functions.php中实现它,上传表单工作,它上传图片,但没有任何到达wordpress。
任何想法为什么?调试时看起来不太好。
有问题的网站: http://web318.login-11.hoststar.at/uni/kleinraum/mitarchpoint/?p=5029 thx提前
//**************************************
// Attachment Insert Form
//**************************************
function insert_attachment_form($postID) {
global $post; $postID = $post->ID;
?>
<form id="file-form" name="file-form" method="POST" action="" enctype="multipart/form-data" >
<input type="file" id="async-upload" name="async-upload" />
<input type="hidden" name="postID" value="<?php echo $postID; ?>" />
<?php wp_nonce_field('client-file-upload', 'client-file-upload'); ?>
<input type="submit" value="Upload" id="submit" name="submit" />
</form>
<?php }
//**************************************
// Process Attachment Form
//**************************************
function process_attachment() {
global $post; $postID = $post->ID;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['client-file-upload'], 'client-file-upload') ) {
return $post->ID;
}
return $post->ID;
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_FILES )) {
require_once(ABSPATH . 'wp-admin/includes/admin.php');
$id = media_handle_upload('async-upload', $_POST['postID']);
unset($_FILES);
}
}
add_action('init', 'process_attachment');
答案 0 :(得分:0)
WordPress提供了以下示例: http://codex.wordpress.org/Function_Reference/media_handle_upload
请务必检查所提供的示例是否出现错误,以及您是否已设置服务器所需的权限。