【发布时间】:2016-05-11 14:54:29
【问题描述】:
// POST -- PARSE / PROCESSING
if (!empty($_POST)):
global $rjw_file = $_FILES["rjw_settings"]["name"]["rjw_file_src"] or die();
endif;
function rjw_settings_section_callback( ) {
// Display text if WooCommerce is disabled.
if ( !in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins'))))
echo "Please Activate WooCommerce";
print_r($_POST);
echo ("<br/><br/><br/>");
print_r($_FILES);
echo("<br/><br/><br/>");
print_r($rjw_file);
}
function rjw_options_page( ) {
?>
<form action="" method='post' enctype="multipart/form-data">
<h2>CSV Stock Import</h2>
<?php
settings_fields( 'pluginPage' );
do_settings_sections( 'pluginPage' );
submit_button();
?>
</form>
<?php
}
所以在上面,$_FILES 打印一个填充的数组。设置变量不 导致脚本死掉,就像使用 ["rjw_file_src"]["name"] 一样。 尽管如此, rjw_file 始终为 null 并且从不打印(并且 var_dump 状态为 NULL) 有没有办法纠正这个问题?我打算处理一个 CSV 文件 并在我完成后删除,所以它不需要是永久上传我只是 需要访问内容。现在我连名字都叫不出来哈哈——尽管 它被打印到屏幕上就好了。
$_FILES 返回的数组:
Array ( [rjw_settings] =>
Array (
[name] => Array ( [rjw_file_src] => Ayk_beN5.jpeg )
[type] => Array ( [rjw_file_src] => image/jpeg )
[tmp_name] => Array ( [rjw_file_src] => /tmp/phpio5xgf )
[error] => Array ( [rjw_file_src] => 0 )
[size] => Array ( [rjw_file_src] => 7691 )
)
)
【问题讨论】:
标签: php wordpress file variables null