Download script

Status
Niet open voor verdere reacties.

Joren 007

Gebruiker
Lid geworden
16 nov 2004
Berichten
905
Hallo allemaal,

Als je op een HTML site bijv. een mp3 bestandje zet, kan je dat alleen downloaden door Doel opslaan als..., anders speelt hij hem gelijk af. Nu zoek ik een scriptje waarmee hij het downloadvenster opent, en niet de Media Speler.

Alvast bedankt,

Joren
 
puur via html is dit niet mogelijk, via php echter wel

Hier heb je n script dat ik heb gebruikt (werkt via argument in de link)

PHP:
<?php
$illegal = false;
if (isset($_GET['file']) && !empty($_GET['file']))
{
	/* check the filevar and give the correct fileHandle */
	$fh = "";
	switch ($_GET['file']) {
		case "mp31" : $fh = "1.mp3";
			break;
		case "mp32" : $fh = "2.mp3";
			break;
	}
	/* quit or load the file */
	if ($fh == "") {
		$illegal = true;
	} else {
		$bestand = /*"http://map_naar_de_files" . $fh;*/
		$len = filesize($bestand);
		$newname = "soundserie_" . $fh;
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: public");
		header("Content-Description: File Transfer");
		$header = "";
		$type = substr($_GET['file'], 0, 3);
		switch ($type) {
			case "mp3" : $header = "Content-Type: audio/mp3";
				break;
		}
		header($header);
		if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
			$header = "Content-Disposition: filename=".$fh.";";
		} else {
			$header = "Content-Disposition: attachment; filename=".$fh.";";
		} 
		header($header);
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".$len);
		readfile ($bestand);
		
		ob_flush();
		flush();
	}
} else {
	$illegal = true;
}

if ($illegal) {
	echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
	echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
	echo "<head>\n";
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
	echo "<title>downloading</title>\n";
	echo "</head>\n";
	echo "\n";
	echo "<body>\n";
	echo "File not found!\n";
	echo "</body>\n";
	echo "</html>\n";
}
?>

--Johan
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan