Unable to get ID3 data
-
I’m trying to retrieve the ID3 tags of an mp3 file and I’m using the following code for testing.
<?php $uploads = wp_upload_dir(); $uploads_dir = ( $uploads['baseurl'] . $uploads['subdir'] ); $file_path = $uploads_dir . "/song.mp3"; $metadata = wp_read_audio_metadata( $file_path ); echo "This song is played by " . $metadata['artist']; var_dump($metadata); ?>I took the first 4 lines from an example in the codex, and
$file_pathdoes display the correct url when printed.The echoed string doesn’t display the artist name and the
var_dumpreturns abool(false).I pasted this code in header.php, but the result was the same.
if ( !function_exists( 'wp_read_audio_metadata' ) ) { require_once ABSPATH . '/wp-admin/includes/media.php'; }Strangely, the
wp_read_audio_metadatafunction works perfectly fine when I use the ACF plugin to supply the file (even without including media.php), but directly providing an url doesn’t seem to work.Am I missing something? Any help is appreciated!
-
I found out that it has something to do with the url. The url returned by the first 3 lines of php above is exactly the same as the url that I see when I go to the Media Library in the Dashboard.
But when I use the
attachment_url_to_postidfunction to get the id of the file and then use theget_attached_filefunction to get the url, it gives me a different url, one that actually works.So my question now is:
Why doesn’t an url like this work?:
subdomain.domain.com/wp-content/uploads/2017/07/song.mp3
And why does an url like this work?:
/home/laurexn109/domains/domain.com/public_html/subdomain/wp-content/uploads/2017/07/song.mp3(/home/laurexn109/domains/ is from the server my website is hosted on)
Note: having /home/laurexn109/domains/ in front of it is actually required for it to work.
How is it possible that neither of these, nor files hosted elsewhere work?
– http://subdomain.domain.com/wp-content/uploads/2017/07/song.mp3
– http://www.domain.com/public_html/subdomain/wp-content/uploads/2017/07/song.mp3
The topic ‘Unable to get ID3 data’ is closed to new replies.