fishdish Posted February 1, 2009 Share Posted February 1, 2009 I think all I am doing wrong is not having the root directory. Where do I find out the root directory for my yahoo hosted website, and how do i properly enter it into this script. <?php $mp3 = $_GET['mp3']; $file = '/home/mp3/'.$mp3; if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } if ( file_exists($file) ) { header("Pragma: public"); header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/mp3"); header('Content-Disposition: attachment; filename="'.$mp3.'"'); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".@filesize($file)); set_time_limit(0); @readfile($file) OR die("<html><body OnLoad=\"javascript: alert('Unable to read file!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>"); exit; } else { die("<html><body OnLoad=\"javascript: alert('File not found!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/ Share on other sites More sharing options...
premiso Posted February 1, 2009 Share Posted February 1, 2009 $_SERVER['DOCUMENT_ROOT'] Should give you that information. <?php $mp3 = $_GET['mp3']; $file = '/home/mp3/'.$mp3; if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } if ( file_exists($file) ) { header("Pragma: public"); header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/mp3"); header('Content-Disposition: attachment; filename="'.$mp3.'"'); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".@filesize($_SERVER['DOCUMENT_ROOT'] . "/" . $file)); set_time_limit(0); @readfile($_SERVER['DOCUMENT_ROOT'] . "/" . $file) OR die("<html><body OnLoad=\"javascript: alert('Unable to read file!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>"); exit; } else { die("<html><body OnLoad=\"javascript: alert('File not found!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>"); } ?> Is how you would use it. Quote Link to comment https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/#findComment-751706 Share on other sites More sharing options...
fishdish Posted February 1, 2009 Author Share Posted February 1, 2009 Whoa, wait. Where? Where do I do this stuff? I am completely new to php and so very frustrated. Where do I use that code you suggested? Please, someone just walk me through this step by step....I've been at this all day trying to learn and I am so very lost. Quote Link to comment https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/#findComment-751710 Share on other sites More sharing options...
premiso Posted February 1, 2009 Share Posted February 1, 2009 Ummmmmm All I did was add it two places. And now thinking about it there is a 3rd place that needs it too: if ( file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $file) ) { Place one header("Content-Length: ".@filesize($_SERVER['DOCUMENT_ROOT'] . "/" . $file)); Place two @readfile($_SERVER['DOCUMENT_ROOT'] . "/" . $file) OR die("<html><body OnLoad=\"javascript: alert('Unable to read file!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>"); Reason being, that is where you access the file etc, and since you want the full path that is how it works. The string contained in $_SERVER['DOCUMENT_ROOT'] is something like "/path/to/your/root". Hope that makes a bit more sense. Quote Link to comment https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/#findComment-751713 Share on other sites More sharing options...
fishdish Posted February 1, 2009 Author Share Posted February 1, 2009 Ok.....so docu_root will be replaced with the root to my directory....but where do i find that directory....from something I read I understand that it is NOT my url....its something else...but how to i find it? my thanks on fixing the code....but i need to know where to find the root directory for my website or is it simply backslashes instead of periods....am i overcomplicating this? Quote Link to comment https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/#findComment-751718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.