andrew_U Posted April 9, 2008 Share Posted April 9, 2008 so i contacted a band with permission to play their song on my website. they said i can use it, but it cannot be downloaded. so i uploaded the .mp3 file i wanted to use and set the permissions so it could not be downloaded. but now the file will not play, because of the permissions change. i want to be able to use this simple script: <embed src="http://undignifiedconference.com/xxxxxxxx.mp3" autostart="true" loop="true"></embed> to play a music file "grabbed" by php is this possible? i am not that familiar with php and the code i tried to use was file_get_contents. Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/ Share on other sites More sharing options...
andrew_U Posted April 9, 2008 Author Share Posted April 9, 2008 sorry i forgot to include what i did to the file_get_contents script, i think i tried this: <php? $filename = ['xxxxxxx.mp3']; $flags = ['FILE_TEXT']; $context = ['NULL']; $offset = ['0'] $maxlen = ['999999999'] string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] ) help cuz i don't really know what i am doing haha Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-512651 Share on other sites More sharing options...
NikkiLoveGod Posted April 9, 2008 Share Posted April 9, 2008 The problem lays with the permissions, the webserver doesn't have the rights to read the .mp3. What I would do, in your situation; I would move the .mp3 ABOVE the webtree. so this means that if you have a webserver that has path like this: c:/server/www/yoursite/index.php ( or linux /var/www/yoursite/index.php ) or something, and everything you put into www folder be available for anyone to read from all around the internet. Now you move the .mp3 to the c:/server/ folder which is above the webtree and thus not available to ppl on the internet, but still readable and playable by the webserver. Then just embed it with relative path, like src='../../../file.mp3'... Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-512692 Share on other sites More sharing options...
discomatt Posted April 9, 2008 Share Posted April 9, 2008 It doesn't matter. If they can hear it then they've probably got it cached, aka downloaded. You could always throw it into a flash jukebox... but even that is cached. I'm sure when they say 'cannot be downloaded' they probably mean have a link on your website for a download. I think the flash jukebox is the best option. Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-512763 Share on other sites More sharing options...
andrew_U Posted April 9, 2008 Author Share Posted April 9, 2008 ok thanks for the help Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-513388 Share on other sites More sharing options...
phpSensei Posted April 9, 2008 Share Posted April 9, 2008 I would include a ajax script that users cant access, and include it to the page where you want to play your song. The ajax would send vars to a PHP file that echos the filename, the filename of the mp3 should be hashed or renamed to something impossible to guess. Then the Ajax would put the filename into a <div></div> tag, which users cant see with view page source. You should also super rename the php file too, if someone gets lucky(like winning the lottery lucky)..... this is my method to be safe.. PHP FILE <?php // AJAX VARS POST METHOD $activate = $_POST['act']; if($activate == '1'){ // echo impossible filename to guess } ?> The OBJECT response text would change the div tag's innerHTML to the filename, or something like function getXMLHttpObject(){ var r; if(window.XMLHttpRequest){ r = new XMLHttpRequest(); }else if(window.ActiveXObject){ r = new ActiveXObject('Microsoft.XMLHTTP'); }else{ alert('Please enable Javascript'); } return r; } var obj = getXMLHttpObject(); function getSong(){ obj.send('POST','ksdjk3j4lk23j4lk3jlkrjelkfjkfjlksdfjr923r23r3jr.php', true); obj.onreadystatechange = handleSong; obj.send('act=1'); } function handleSong(){ if(obj.readyState == 4 && obj.status == 200){ var response = obj.responseText; if(response){ document.getElementById('divSONG').innerHTML = '<embed src="http://undignifiedconference.com/'+response+'" autostart="true" loop="true"></embed>'; // } } } HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script scr="ajaxScript.php"></script> </head> <body> <div id="divSONG"></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-513401 Share on other sites More sharing options...
phpSensei Posted April 9, 2008 Share Posted April 9, 2008 EDIT HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script scr="ajaxScript.php"></script> </head> <body onload="getSong();">> <div id="divSONG"></div> </body </html> Link to comment https://forums.phpfreaks.com/topic/100261-i-need-help-with-a-file-i-dont-want-downloaded/#findComment-513407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.