Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress自定义插件上传图像_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php Wordpress自定义插件上传图像

Php Wordpress自定义插件上传图像,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在编写一个自定义wordpress插件,允许用户将图像上传到文件夹。 我在将实际图像保存到文件夹时遇到问题 这是我的myplugin.php add_action( 'admin_menu', 'register_my_custom_menu_page' ); function register_my_custom_menu_page(){ add_menu_page( 'Home Page', 'Home Page', 'manage_options', 'homepage',

我正在编写一个自定义wordpress插件,允许用户将图像上传到文件夹。 我在将实际图像保存到文件夹时遇到问题

这是我的myplugin.php

add_action( 'admin_menu', 'register_my_custom_menu_page' );

function register_my_custom_menu_page(){
    add_menu_page( 'Home Page', 'Home Page', 'manage_options', 'homepage', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 ); 
}

function my_custom_menu_page(){
    echo '<h1>Settings</h1>';
    echo '<form method="post" action="process.php" enctype="multipart/form-data">';
    echo '<table>';

    echo '<tr><td>Image 1</td><td><input type="file" name="file1" size="40"></td></tr>';    
    echo '<tr><td></td><td><input type="submit" name="submit" value="Update" /></td></tr>';     
    echo '</table>';
    echo '</form>';
 }

您不需要为此使用PHP本机函数

Wordpress提供处理上传并显式移动上传的功能

用法(在您的情况下):


cul_中心的钥匙是什么?
move_uploaded_file($_FILES["cul_center"]["tmp_name"], wp_upload_dir().$_FILES["file1"]["name"]);
require_once( ABSPATH . 'wp-admin/includes/file.php' ); // require file.php

$uploadedfile = $_FILES['file1']; // your file input

$upload_overrides = array( 'test_form' => false ); // you need to do this according to docs

$movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); //let it handle uploads

if ( $movefile ) {
    echo "File is valid, and was successfully uploaded.\n";
    var_dump( $movefile); // will print associative array of file attributes.
}