Great snippet - I’m completely new to Modx and trying to get my head around it. I’ve also been trying to protect (to some extent- never completely possible) MP3’s on the website I’m working on so was very attracted to the URL encryption.
Just a tip for anyone else in the same position: Whilst the song file names are encrypted in the flash player embed script, you can still see the full path to MP3’s - at least I could in Safari’s activity window. To get round this I put the MP3’s above the web root and created a php file that I put in the assets/media folder which I reference in the call to mPlayer instead of the MP3 itself. The php file reads the content of the MP3 and passes it on to mPlayer so the MP3 is never called client side. Not sure how foolproof this is but for any one interested:
php code in song.php:
$filepath='/home/username/music/file.mp3';
$filename='file.mp3';
header('Content-type: audio/mpeg');
header('Content-Length: '.filesize($filepath));
header('Content-Disposition: filename-"'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
readfile($filepath);
exit;
Works in Firefox (Mac) and Safari (Mac) - not tested on internet explorer or windows yet.
On second thoughts still not secure - if you access the php file directly you can still right click and save as an mp3. Trying to figure out a way to pass a variable from the mplayer to the php file so it wont read the file if accessed someother way. Any thoughts?