src/class-wp-image.php
public static function upload( $url, $filename ) {

		$dir = wp_upload_dir();

		if ( ! isset( $dir['path'], $dir['basedir'] ) ) {
			return false;
		}

		$path = wp_mkdir_p( $dir['path'] ) ? $dir['path'] : $dir['basedir'];
		$path = rtrim( $path, '/' ) . '/';

		$image_data = @file_get_contents( $url );

		if ( $image_data ) {
			$state = @file_put_contents( $path . $filename, $image_data );
		}

		return ( isset( $state ) && $state ) ? $path . $filename : false;
	}
public static function upload( $url, $filename ) {

		$dir = wp_upload_dir();

		if ( ! isset( $dir['path'], $dir['basedir'] ) ) {
			return false;
		}

		$path = wp_mkdir_p( $dir['path'] ) ? $dir['path'] : $dir['basedir'];
		$path = rtrim( $path, '/' ) . '/';

		$image_data = @file_get_contents( $url );

		if ( $image_data ) {
			$state = @file_put_contents( $path . $filename, $image_data );
		}

		return ( isset( $state ) && $state ) ? $path . $filename : false;
	}
public static function upload ( $ url , $ filename ) { $ dir = wp_upload_dir ( ) ; if ( ! isset ( $ dir [ 'path' ] , $ dir [ 'basedir' ] ) ) { return false ; } $ path = wp_mkdir_p ( $ dir [ 'path' ] ) ? $ dir [ 'path' ] : $ dir [ 'basedir' ] ; $ path = rtrim ( $ path , '/' ) . '/' ; $ image_data = @ file_get_contents ( $ url ) ; if ( $ image_data ) { $ state = @ file_put_contents ( $ path . $ filename , $ image_data ) ; } return ( isset ( $ state ) && $ state ) ? $ path . $ filename : false ; }
Upload image to WordPress upload directory.

@since 1.0.2

@param string $url      → external url image.
@param string $filename → filename.

@return string|false → path to upload image or false on failure.
Upload image to WordPress upload directory .