我已经在 stackoverflow 上浏览了将近 2 个小时来寻找答案。通过在这里阅读一些答案,我已经设法使我的文件上传功能很好。但这一次是没有办法的。我真的需要问一下上传后如何保存上传文件的路径。看,我在我的 wordpress 插件中使用了 uploadify。我所做的是将上传的文件(准确地说是.pdf)保存到我目录上的特定文件夹中。然后我想要的是在发布帖子时保存保存文件的路径。所以从技术上讲,上传后,我希望在帖子中的某处有上传文件的路径,这样当我发布帖子时,路径也将保存在数据库中。这甚至可能吗?
这是我插件中的代码片段,
/* Displays the box content which is the dropdown list of Funds */
function wnm_pengana_investor_upload_investor_box( $post ) {
/* Use nonce for verification */
wp_nonce_field( plugin_basename( __FILE__ ), 'wnm_pengana_funds_noncename' );
echo '<p class="uploadify_container">';
echo '<label style="margin-left: 15px;" for="investor_file_upload">Upload one or more files at once.</label>';
echo '<input type="file" name="investor_file_upload" id="investor_file_upload" />';
echo '</p>';
}
/* When the post is saved, saves our custom data */
function wnm_pengana_save_investor_upload_box( $post_id ) {
/*verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything */
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
/* verify this came from the our screen and with proper authorization,because save_post can be triggered at other times */
if ( !wp_verify_nonce( isset($_POST['wnm_pengana_funds_noncename']), plugin_basename( __FILE__ ) ) )
return;
// Check permissions
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
// OK, we're authenticated: we need to find and save the data
$mydata = $_POST['investor_file_upload'];
update_post_meta($post_id, 'uploaded_forms_path', $mydata);
}
目前,发布时,postmeta upload_forms_path 将添加到 postmeta 表中,但它是空的。我想我需要放一些东西,`echo '<input type="file" name="investor_file_upload" id="investor_file_upload" />';
遗憾的是我不知道我该放什么。谁能帮我?谢谢。`