返回介绍

wp_handle_upload()

发布于 2017-09-11 12:10:30 字数 3595 浏览 1080 评论 0 收藏 0

wp_handle_upload( array $file,  array|bool $overrides = false,  string $time = null )

Wrapper for _wp_handle_upload().


description

Passes the ‘wp_handle_upload’ action.


参数

$file

(array) (Required) Reference to a single element of $_FILES. Call the function once for each uploaded file.

$overrides

(array|bool) (Optional) An associative array of names=>values to override default variables.

Default value: false

$time

(string) (Optional) Time formatted in 'yyyy/mm'.

Default value: null


返回值

(array) On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).


源代码

File: wp-admin/includes/file.php

function wp_handle_upload( &$file, $overrides = false, $time = null ) {
	/*
	 *  $_POST['action'] must be set and its value must equal $overrides['action']
	 *  or this:
	 */
	$action = 'wp_handle_upload';
	if ( isset( $overrides['action'] ) ) {
		$action = $overrides['action'];
	}

	return _wp_handle_upload( $file, $overrides, $time, $action );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-admin/includes/file.php: _wp_handle_upload()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::upload_from_file()
  • wp-admin/includes/class-file-upload-upgrader.php: File_Upload_Upgrader::__construct()
  • wp-admin/includes/media.php: media_handle_upload()
  • wp-admin/includes/import.php: wp_import_handle_upload()
  • wp-admin/custom-header.php: Custom_Image_Header::step_2_manage_upload()
  • wp-admin/custom-background.php: Custom_Background::handle_upload()
  • Show 1 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    
    if ( ! function_exists( 'wp_handle_upload' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }
    
    $uploadedfile = $_FILES['file'];
    
    $upload_overrides = array(
    	'test_form' => false
    );
    
    $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
    
    if ( $movefile && ! isset( $movefile['error'] ) ) {
        echo __( 'File is valid, and was successfully uploaded.', 'textdomain' ) . "\n";
        var_dump( $movefile );
    } else {
        /*
         * Error generated by _wp_handle_upload()
         * @see _wp_handle_upload() in wp-admin/includes/file.php
         */
        echo $movefile['error'];
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文