Jump to content

Need help with Download button script


fishdish

Recommended Posts

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>");

}

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/143324-need-help-with-download-button-script/
Share on other sites

$_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.

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.

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.