2

私は1つの問題に直面しています。問題を介して記事を送信するフォームがあり$.ajax()ます。ファイルをアップロードするオプションをユーザーに提供していて、ページを更新したくないので、記事を送信するメインフォーム内にアップロードフォームを配置しました。フォームをネストできないようです。また、$_FILES配列内のファイルの値も必要です。

これが私のHTMLフォームです:

<form action="/" id="upload-form">
    <fieldset>
        <p class="upload-result">
        <!-- result of upload goes here -->
        </p>
        <p class="upload-images">
            <label><?php _e('Upload Images','sofa'); ?></label><a href="" class="button-secondary img_add_upload"><?php _e('Upload Image','sofa'); ?></a><a href="" class="button-secondary img_add_url"><?php _e('Add Image URL','sofa'); ?></a>
        </p>
        <p class="upload-url">
            <input type="text" name="img_url" id="img_url" value="<?php _e('Enter URL of image here...','sofa'); ?>" /><a href="" class="button-secondary img_add"><?php _e('Add Image','sofa'); ?></a>
        </p>
        <p class="upload-file">
            <input type="file" id="async-upload" name="async-upload" size="47" /><a href="" class="button-secondary img_upload"><?php _e('Upload','sofa'); ?></a>
        </p>
        <ol class="upload-images-lib">
            <li></li>
        </ol><div class="clear"></div>
        <p class="upload-images-note"><?php printf(__('Click on image to view full size. To mark image as main/featured, add image then click on %s icon.','sofa'), '<img src="'.get_bloginfo('template_directory').'/img/box.png" alt="" />'); ?></p>
        <p class="upload-input">
            <label for="utitle"><?php _e('Title','sofa'); ?></label>
            <input type="text" name="utitle" id="utitle" value="" />
            <span><?php _e('Enter a good title that describes what you are publishing. Be creative!','sofa'); ?></span>
        </p>
        <p class="upload-input">
            <label for="cat"><?Php _e('Category','sofa'); ?></label>
            <?php wp_dropdown_categories('hide_empty=0'); ?>
        </p>
        <p class="upload-editor">
            <?php wp_editor( '', 'ucontent', $settings = array(
                'textarea_rows' => 8,
                'textarea_name' => 'ucontent'
            )); ?>
        </p>
        <p class="upload-input">
            <label for="utags"><?php _e('Tags','sofa'); ?></label>
            <input type="text" name="utags" id="utags" value="" />
            <span><?php _e('Enter a comme seperated list of tags that perfectly describe your post. e.g. funny, man, public','sofa'); ?></span>
        </p>
        <p class="upload-submit">
            <input type="submit" value="<?php _e('Publish','sofa'); ?>" class="gradient-link-normal" />
        </p>
    </fieldset>
</form>

問題はこの部分にあります。

<p class="upload-file">
    <input type="file" id="async-upload" name="async-upload" size="47" /><a href="" class="button-secondary img_upload"><?php _e('Upload','sofa'); ?></a>
</p>

これをクリックすると、ファイルのアップロードを処理したいのですが、ファイルのアップロードを行うPHPフォームには、$_FILES明らかに配列が必要です。

これが可能かどうかはわかりません。解決策はありますか?

4

2 に答える 2

2

jQueryプラグインを使用してファイルのアップロードを処理し、fromからの残りのデータを既に行っているように処理する必要があります。

ファイルのアップロードを実行するための既製のプラグインがいくつかあります。

ajaxアップロードを評価します

jQuery複数ファイルアップロードプラグイン

AjaxFileUpload

jQueryファイルのアップロード

詳細については、jQueryのプラグインサイトをご覧ください。

于 2012-06-02T20:14:28.083 に答える
1

ページ上の別の場所にネストされたフォームを配置し、[アップロード]ボタンをクリックした場合にのみフォームを表示するための最良の方法。

アップロードフォーム(小さなフォーム)は最初は見えません。ポップアップまたはjqueryコードを使用して表示できます。

<div id="smallform">
    <form name="upload">
        <input type="file" name="picture">
        <input type="submit" name="upload" value="Upload">
    </form>
</div>

<div id="largeform">
<form name="details">
    <input name="detail1">
    <input name="detail2">
     <a href="#" onclick="showSmallForm()">Upload file</a>
    <input type="submit">
</form>
</div>

関数showSmallForm()は、アップロードをクリックすると、小さいフォームを大きいフォームに表示します。

于 2016-02-03T18:54:20.953 に答える