簡體   English   中英

Wordpress:在管理菜單的自定義頁面中加載文件時出現問題

[英]Wordpress : Problem to load a file in a custom page in admin menu

我需要創建一個插件以在管理菜單中添加頁面。 在此頁面中,我想選擇一個文件並對它進行一些處理。 我創建了一個簡單的自定義頁面,其中包含一個文件上傳字段和一個提交按鈕,但是我無法管理“提交按鈕”操作。 如果有人可以給我一些想法...

感謝克里希納,我在表單中添加了一個操作,但是當我單擊“提交”按鈕時,我可以看到代碼中的第一條消息(“我已讀取文件...”),但是看不到第二條消息(“文件已填充”) )。

有什么想法嗎?

這是我的插件文件定義:fileuploadplugin.php:

<?php
/*
Plugin Name:  File upload Plugin
Description:  Plugin for uploading file
Version:      1.0
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
     die;
}

/*
    Action for menu definition
*/
add_action('admin_menu', 'fileuploadplugin_menu');

/*
    Menu definition
*/
function fileuploadplugin_menu () {
    add_menu_page('File upload plugin', 'File upload', 'manage_options', 'fileuploadlogin', 'file_upload_plugin_page' );
}

/*
    Display a page with file input field and submit button
*/
function file_upload_plugin_page () {
    if(isset($_POST['submit'])) {
        // actions to do on the file : read it, manage it, and so on
        echo "I read the file and do what I have to do !";
        if(isset($_FILES['filetoupload'])) {
            echo "File is filed, I can read it!";
        }
    }
    ?>
    <div class="container">
        <h1>Upload file</h1>
        <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"  enctype="multipart/form-data">
        <input type='file' id='filetoupload' name='File to upload : '></input>
        <?php submit_button('Upload file') ?>
        </form>
    </div>
    <?php
}

?>

您可以嘗試使用以下代碼在提交表單后返回同一頁面。

<form action ="<?php echo $_SERVER['REQUEST_URI']; ?>" method ="post" enctype="multipart/form-data">

更新:

在行下更改

if(isset($_FILES['fichier_resultat'])) {

if(isset($_FILES['filetoupload'])) {

希望這可以幫助。

問題已解決,謝謝您的幫助。

問題實際上出在輸入文件定義中:我為id和name參數使用了2個不同的值。 所以我將其定義從

<input type='file' id='filetoupload' name='File to upload : '></input>

<input type='file' id='filetoupload' name='filetoupload'></input>

再次感謝您的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM