HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/doco2/wp-content/themes/ormedia/wp-admin-site-info.php
<?php
wp_enqueue_media();

// var_dump($_REQUEST);
$site_name = trim($_REQUEST['site_name']);
$site_logo = trim($_REQUEST['site_logo']);
if (!empty($site_name) && !empty($site_logo)) {
    update_option('custom_site_name', $site_name);
    update_option('custom_site_logo', $site_logo);
    echo '<script>alert("更改成功!");</script>';
}
$site_name = get_option('custom_site_name');
$site_logo = get_option('custom_site_logo');
?>

<html>

<head>
    <style type="text/css">

    </style>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            var upload_frame;
            var value_id;
            jQuery('.upload_button').on('click', '', function(event) {
                value_id = jQuery(this).attr('id');
                event.preventDefault();
                if (upload_frame) {
                    upload_frame.open();
                    return;
                }
                upload_frame = wp.media({
                    title: 'Insert image',
                    library: {
                        type: 'image'
                    },
                    button: {
                        text: 'Insert',
                    },
                    multiple: false
                });
                upload_frame.on('select', function() {
                    attachment = upload_frame.state().get('selection').first().toJSON();
                    console.log(attachment);
                    jQuery('input[name=' + value_id + ']').val(attachment.url);
                    jQuery('#preview_site_logo').css('display', 'block');
                    jQuery('#preview_site_logo').attr('src', attachment.url);
                });
                upload_frame.open();
            });
        });
    </script>
</head>

<body>
    <h1></h1>
    <form class="wrap notification" method="post">
        <h3>Site 設定</h3>
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row">站點名稱</th>
                    <td>
                        <input type="text" size="60" value="<?php echo $site_name; ?>" name="site_name" />
                    </td>
                </tr>
                <tr>
                    <th scope="row">站點 Logo</th>
                    <td>
                        <img id="preview_site_logo" src="<?php echo $site_logo; ?>" style="max-width: 200px; <?php echo empty($site_logo) ? "display:none;" : "display:block;"; ?>margin-bottom:10px;">
                        <input type="text" size="60" value="<?php echo $site_logo; ?>" name="site_logo" hidden />
                        <a id="site_logo" class="upload_button button" href="#">選擇媒體文件</a>
                    </td>
                </tr>
            </tbody>
        </table>
        <p class="submit">
            <input type="submit" name="submit" id="submit" class="button button-primary" value="儲存設定">
        </p>

    </form>

</body>

</html>