我有一个WP的插件,它的目的是导入文件(JPG)并收集链接或ID . 所以我尝试从插件文件夹中打开文件并将其插入媒体库WP

foreach ( $ar as $array ){
    $i = $array['sku'];

    $path = plugin_dir_path( __FILE__ ) . 'images/' . $array['sku'] . '.jpg' ;

    $exists = file_exists( $path );
    //$existse = file_exists( 'C:\Users\Victor\Desktop\WP\apps\wordpress\htdocs\wp-content\plugins\sinco_mate\images/930002065858.jpg' );

    if( $exists ){
        foreach (glob( $path) as $filename) {
            //echo "<h3>" . $filename  . "</h3>";

            $upload_overrides = array( 'test_form' => false );



            $img=fopen($filename, "w+");
            $img_try = wp_handle_upload( $img , $upload_overrides);


            if ( $img_try && ! isset( $img_try['error'] ) ) {
                echo "File is valid, and was successfully uploaded.\n";
                var_dump( $img_try );
            } else {
                echo $img_try['error'];
            }

            array_push($array_sort,
                array(
                    'pic'=>$i
                )
            );
        }
    }

我懂了

文件为空 . 请上传更实质的内容 . 此错误也可能是由于php.ini中的上传被禁用或者post_max_size被定义为小于php.ini中的upload_max_filesize .

但我的php.ini就像这样,牧场很小

upload_max_filesize = 100M post_max_size = 100M memory_limit = 128M

如何上传文件?谢谢 .