私が答えを求めてstackoverflowでここを閲覧しているのはほぼ2時間です。ここでいくつかの回答を読むことで、ファイルのアップロードをうまく機能させることができました。でも今回は仕方ないです。アップロード後にアップロードしたファイルのパスを保存する方法を本当に尋ねる必要があります。ほら、ワードプレスプラグインで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" />';
悲しいことに、何を入れたらいいのかわからないので、何かを入れる必要があると思います。誰か助けてもらえますか?ありがとう。`