Toon posts:

Download script mbv Readfile doet het niet in IE

Pagina: 1
Acties:
  • 43 views sinds 30-01-2008

Verwijderd

Topicstarter
Hallo iedereen,

Ik heb een klein download scriptje gemaakt die werkt met mod rewrite. Alle bestanden worden naar rewrite.php gestuurd (behalve php files) en daar probeer ik heb bestand te downloaden. Mijn probleem is dat het niet werkt in IE, maar wel in Mozilla. Hier is mij code:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function clean_path($ch) {
  do {
    $pos = strpos($ch, "//");
    if ($pos !== false) {
      $ch = substr_replace($ch, "/", $pos, 2);
    }
  } while ($pos !== false);
  return $ch;
} 

$filename = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
$filename = clean_path ($filename);

if (strstr($_SERVER['HTTP_USER_AGENT'],"MSIE")) 
  $attachment=""; 
else 
  $attachment=" attachment;"; 

$savename = basename($filename);

$len = filesize($filename);
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: $attachment filename=".$savename);
header("Content-Length: $len");
header("Content-Description: File Transfer");     
@readfile($filename);


Nou test ik dit op een server in mijn eigen netwerk. Als ik dit localhost test doet hij het wel?
Ik heb bijna alle combinaties met headers geprobeerd, maar het wil nog steeds niet lukken.
hebben jullie misschien een idee?

Alvast bedankt.

[ Voor 8% gewijzigd door curry684 op 19-07-2004 11:56 . Reden: [php]-tags hebben we niet voor niets... ]


Verwijderd

header("Content-Length: $len");

Waar wordt $len gevuld?

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Correcte formaat voor Content-Disposition is:

Content-Disposition: attachment; filename="myfilename.ext"

En je hoeft alleen application/octect-stream op te geven als content-type. Dit alles staat letterlijk in de RFC's ondanks dat het geen standaard is van HTTP1.1, en gaat dus op slot :)

Zie ook even de stickies mbt topictitels btw.

Professionele website nodig?


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Verwijderd schreef op 19 juli 2004 @ 11:57:
header("Content-Length: $len");

Waar wordt $len gevuld?
PHP:
1
$len = filesize($filename);   // hier?


;)

Professionele website nodig?


Dit topic is gesloten.