Einzelnen Beitrag anzeigen

Benutzerbild von ATS3788
ATS3788

Registriert seit: 18. Mär 2004
Ort: Kriftel
646 Beiträge
 
Delphi XE Starter
 
#16

AW: Download mit javascript jquery

  Alt 11. Apr 2013, 07:56
Danke Valle dachte ich mir schon, habe das von www.html.de
als Antwort bekommen.

Neuer Ansatz neues Glück.

Code:
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{  //1
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari   //*x
  xmlhttp=new XMLHttpRequest();
  }                                       //*x
else
  {// code for IE6, IE5    //*y
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }                  //*y
xmlhttp.onreadystatechange=function() {   //2
 
 if(xmlhttp.readyState==4){ //3
  switch (xmlhttp.status){  //4
   case 200: {
   var S = xmlhttp.responseText;
    document.getElementById("myDiv").innerHTML= S;
    if (S == "") { document.getElementById("myDiv").innerHTML = "MMMhh"};
    break;
    };
   case 404:
   document.getElementById("myDiv").innerHTML="Download not available !"; break; //(HTTP-Status-Code ist '404')
   case 0:
   document.getElementById("myDiv").innerHTML="Server does not response !"; break; //(HTTP-Status-Code ist '0')
   default:
    log_error("Unknown Error !"); break; //(HTTP-Status-Code ist nicht '200')
  } // 4
 } //  3
}; // 2
xmlhttp.open("GET","download.php",true);
xmlhttp.send();
}; // 1
</script>
</head>
<body>

<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
<div id="myDiv"></div>
</body>
</html>

Zitat:
<?PHP
/**
* Dateien zum Download anbieten
*
* Systemvoraussetzung:
* Linux
* PHP 3, PHP 4, PHP 5
*
* Dateien zum Download anbieten
*
* LICENSE: GNU General Public License (GPL)
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* @category Verschlüsselung
* @author Damir Enseleit <info@selfphp.de>
* @copyright 2001-2006 SELFPHP
* @version $Id: download.php,v 0.10 2006/04/14 13:25:30 des1 Exp $
* @link http://www.selfphp.de
*/

/**
* Erstellt die Navigationsleiste für die einzelnen Seiten
*
* @param string $file Datei, die zum Download steht
* @param string $dir Verzeichnis mit abschließenden Slash (/)
* @param string $type Mime-Type
*
* @return void
*/

function makeDownload($file, $dir, $type)
{

header("Content-Type: $type");

header("Content-Disposition: attachment; filename=\"$file\"");

readfile($dir.$file);

}
// gif - image/gif
// jpg - image/jpeg
// png - image/png
// zip - application/zip
// txt - text/plain

$dir = '/download/';
$type = 'application/zip';
$file = 'Report0.zip';

if(!empty($_GET['file']) && !preg_match('=/=', $_GET['file']))
{
if(file_exists ($dir.$_GET['file']))
{
makeDownload($_GET['file'], $dir, $type);
}
}
?>
OK soweit bin ich nun.
Bekomme sogar xmlhttp.status 200
nur übertragen wird nix.
Hat noch einer eine Idee ?
Martin MIchael

Geändert von ATS3788 (11. Apr 2013 um 08:00 Uhr) Grund: slash vergessen
  Mit Zitat antworten Zitat