因此,我正在上载一个图像文件,该文件可与以下代码一起使用,但它不会出现在媒体库中。我收到一条“文件有效,已成功上载”的消息,但我必须错过一个步骤。
if ( ! function_exists( \'wp_handle_upload\' ) ) {
require_once( ABSPATH . \'wp-admin/includes/file.php\' );
}
$files = array(\'tmp_name\' => $_FILES[$fieldname][\'tmp_name\'],
\'name\' => $_FILES[$fieldname][\'name\']);
$overrides = array( \'test_form\' => false,
\'action\' => \'to_be\',
\'mimes\' => false);
$movefile = @wp_handle_upload( $files, $overrides );
if ( $movefile && !isset( $movefile[\'error\'] ) ) {
echo "File is valid, and was successfully uploaded.\\n";
} else {
/**
* Error generated by _wp_handle_upload()
* @see _wp_handle_upload() in wp-admin/includes/file.php
*/
echo $movefile[\'error\'];