| 1 | <?php
|
|---|
| 2 | // Plugin Name: Get Remote First Bytes
|
|---|
| 3 |
|
|---|
| 4 | function get_remote_first_bytes( $url ) {
|
|---|
| 5 | if ( ! function_exists( 'wp_tempnam' ) ) {
|
|---|
| 6 | require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | // @see download_url()
|
|---|
| 10 | $file = wp_tempnam( $url );
|
|---|
| 11 |
|
|---|
| 12 | $response = wp_remote_get( $url, array(
|
|---|
| 13 | 'stream' => true,
|
|---|
| 14 | 'filename' => $file,
|
|---|
| 15 | 'limit_response_size' => 32768, // 32 KB
|
|---|
| 16 | ) );
|
|---|
| 17 |
|
|---|
| 18 | echo size_format( filesize( $file ) );
|
|---|
| 19 |
|
|---|
| 20 | unlink( $file );
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | $url = 'https://archive.org/download/corblund2013-03-14.matrix.flac/corblund2013-03-14track09.mp3';
|
|---|
| 24 | get_remote_first_bytes( $url );
|
|---|