[php]force download

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ik heb al tig verschillende scripts op internet gevonden. Ze lijken allemaal op elkaar, maar geen van allen doet het :|

Ik denk dat het probleem is dat de files die gedownload moeten worden op een andere computer staan als waar het script op draait. Dus nu is mijn vraag:

Hoe kan ik ervoor zorgen dat het dan toch gedownload wordt(met zo'n "save as"-dialog)?

Deze doet het nog het beste, hij download namelijk wel iets van het goede aantal kb, maar het plaatje(jpg) kan ik niet openen. hier het script:

PHP:
1
2
3
4
5
6
$file="//1a-server/projects/naam.jpg";
$filename=basename($file);
header("Cache-control: private");
header ("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
readfile($file);


ik heb de file-aanroep erbij geschreven voor de duidelijkheid


ik heb ook scripts als deze geprobeerd:

PHP:
1
2
3
4
5
6
$file="//1a-server/projects/naam.jpg";
$filename=basename($file);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
$fn = fopen("$file" , "r");
fpassthru($fn);


maar die werken al helemaal niet. Deze foutmelding krijg ik:
"Internet Explorer was unable to open this Internet site. The request site is either unavailable or cannot be fount. please try again later."

[ Voor 16% gewijzigd door Verwijderd op 22-04-2004 11:51 ]


Acties:
  • 0 Henk 'm!

  • pasta
  • Registratie: September 2002
  • Laatst online: 12-01 14:16

pasta

Ondertitel

Ik denk dat je de Content-Type moet aanpassen naar iets wat altijd gedownload _moet_ worden.

Signature


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
met deze content types doet hij het ook niet:

header("Content-Type: image/jpg");
header("Content-Type: image/jpeg");
header("Content-Type: image/force-download");
header("Content-Type: application/force-download");

Hij download wel iets van 296kb, maar als ik hem wil openen krijg ik zo'n plaatje met een kruisje

Acties:
  • 0 Henk 'm!

  • pasta
  • Registratie: September 2002
  • Laatst online: 12-01 14:16

pasta

Ondertitel

Ik duidde meer op iets in de richting van een random extensie, die met geen 1 programma valt te openen. Overigens bestaan die force-download MIME-types niet. Zie ook deze pagina bijvoorbeeld.

Signature


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
ik snap niet wat je bedoeld eerlijk gezegd. Maar stel dat het altijd een jpg is, dan moet...

Header("Content-Type: image/jpeg");

...toch werken?

Acties:
  • 0 Henk 'm!

  • thomaske
  • Registratie: Juni 2000
  • Laatst online: 19-09 09:34

thomaske

» » » » » »

open het plaatje eens in een text-editor. Misschien staan er php errors in waar je wat aan hebt.

Brusselmans: "Continuïteit bestaat niet, tenzij in zinloze vorm. Iets wat continu is, is obsessief, dus ziekelijk, dus oninteressant, dus zinloos."


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
dit staat erin:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script language="JavaScript">
function setCompany(company) {
var form = document.frmCompany;
if (company) {
form.company_id.value = company;}
form.submit();}

function setLang(langs) {
var form = document.frmLang;
if (langs) {
form.lang.value = langs;}
form.submit();}

function doBtn() {
var oEl = event.srcElement;
var doit = event.type;

while (-1 == oEl.className.indexOf( "Btn" )) {
oEl = oEl.parentElement;
if (!oEl) {
return;
}
}
if (doit == "mouseover" || doit == "mouseup") {
oEl.className = "clsBtnOn";
} else if (doit == "mousedown") {
oEl.className = "clsBtnDown";
} else {
oEl.className = "clsBtnOff";
}
}
function tboff(){
var oEl = event.srcElement;
var doit = event.type;
oEl.className = "topBtnOff";
}

</script>
<title>GROUPA</title>
<link rel="stylesheet" type="text/css" href="./style/default/main.css" media="all" />
<style type="text/css" media="all">@import "./style/default/main.css";</style>
</head>

<body bgcolor="#FFFFFF">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<!--DWLayoutTable-->
<form name="frmCompany" action="#" method="post">
<input type="hidden" name="company_id" value="0" />
</form>
<form name="frmLang" action="#" method="post">
<input type="hidden" name="lang" value="0" />
</form>

<table width="99%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>


en dan enorm veel van dit soort regels:

ÈêC}jñ1tn.%±é5$ž Ô÷”¥ë¶çÄþF žA—ʽÓãÊp ÝS§Ý…ŒÉ©î,´Ï­H…¿½T "`ñåN²£“Ú˜È2‘ûÑ þ|C á‘Ä~HAȓړ“Å1ŽÑÄÈí@K"6’3"¬[êZÛn»576¡‘¹·øÕp´¬#žhI92 Ó


en dan:

</td>
</tr>
</table>
</body>
</html>


er klopt dus inderdaad iets helemaal niet, maar het gaat boven mijn pet , want waarom maakt hij html tags aan als het om een jpg gaat?

Acties:
  • 0 Henk 'm!

  • stekkel
  • Registratie: Augustus 2001
  • Laatst online: 17-09 08:05
Uit de SquirrelMail source code (GPL):

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
 * function SendDownloadHeaders - send file to the browser
 *
 * Original Source: SM core src/download.php
 * moved here to make it available to other code, and separate
 * front end from back end functionality.
 *
 * @param string $type0 first half of mime type
 * @param string $type1 second half of mime type
 * @param string $filename filename to tell the browser for downloaded file
 * @param boolean $force whether to force the download dialog to pop
 * @param optional integer $filesize send the Content-Header and length to the browser
 * @return void
 */
 function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {
     global $languages, $squirrelmail_language;
     $isIE = $isIE6 = 0;

     sqgetGlobalVar('HTTP_USER_AGENT', $HTTP_USER_AGENT, SQ_SERVER);

     if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&
         strstr($HTTP_USER_AGENT, 'Opera') === false) {
         $isIE = 1;
     }

     if (strstr($HTTP_USER_AGENT, 'compatible; MSIE 6') !== false &&
         strstr($HTTP_USER_AGENT, 'Opera') === false) {
         $isIE6 = 1;
     }

     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
         function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
         $filename =
         $languages[$squirrelmail_language]['XTRA_CODE']('downloadfilename', $filename, $HTTP_USER_AGENT);
     } else {
         $filename = ereg_replace('[\\/:\*\?"<>\|;]', '_', str_replace('&nbsp;',
 ' ', $filename));
     }

     // A Pox on Microsoft and it's Internet Explorer!
     //
     // IE has lots of bugs with file downloads.
     // It also has problems with SSL.  Both of these cause problems
     // for us in this function.
     //
     // See this article on Cache Control headers and SSL
     // http://support.microsoft.com/default.aspx?scid=kb;en-us;323308
     //
     // The best thing you can do for IE is to upgrade to the latest
     // version
     //set all the Cache Control Headers for IE
     if ($isIE && !$isIE6) {
         header ("Pragma: public");
         header ("Cache-Control: no-store, max-age=0, no-cache, must-revalidate");# HTTP/1.1
         header ("Cache-Control: post-check=0, pre-check=0", false);
         header ("Cache-control: private");

         //set the inline header for IE, we'll add the attachment header later if we need it
         header ("Content-Disposition: inline; filename=$filename");
     }

     if (!$force) {
         // Try to show in browser window
         header ("Content-Disposition: inline; filename=\"$filename\"");
     } else {
         // Try to pop up the "save as" box

         // IE makes this hard.  It pops up 2 save boxes, or none.
         // http://support.microsoft.com/support/kb/articles/Q238/5/88.ASP
         // http://support.microsoft.com/default.aspx?scid=kb;EN-US;260519
         // But, according to Microsoft, it is "RFC compliant but doesn't
         // take into account some deviations that allowed within the
         // specification."  Doesn't that mean RFC non-compliant?
         // http://support.microsoft.com/support/kb/articles/Q258/4/52.ASP

         // all browsers need the application/octet-stream header for this
         header ("Content-Type: application/octet-stream; name=\"$filename\"");

         // http://support.microsoft.com/support/kb/articles/Q182/3/15.asp
         // Do not have quotes around filename, but that applied to
         // "attachment"... does it apply to inline too?
         header ("Content-Disposition: attachment; filename=\"$filename\"");

         if ($isIE && !$isIE6) {
             // This combination seems to work mostly.  IE 5.5 SP 1 has
             // known issues (see the Microsoft Knowledge Base)

             // This works for most types, but doesn't work with Word files
             header ("Content-Type: application/download; name=\"$filename\"");

             // These are spares, just in case.  :-)
             //header("Content-Type: $type0/$type1; name=\"$filename\"");
             //header("Content-Type: application/x-msdownload; name=\"$filename\"");
             //header("Content-Type: application/octet-stream; name=\"$filename\"");
         } else {
             // another application/octet-stream forces download for Netscape
             header ("Content-Type: application/octet-stream; name=\"$filename\"");
         }
     }

     //send the content-length header if the calling function provides it
     if ($filesize > 0) {
         header("Content-Length: $filesize");
     }

}  // end fn SendDownloadHeaders

[ Voor 14% gewijzigd door stekkel op 22-04-2004 12:20 ]


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Okay ik ben eruit, ik riep het script aan via een ander script die html tags in zichzelf heeft.Je moet dus het script direct aanroepen

Acties:
  • 0 Henk 'm!

  • sjoerdb2
  • Registratie: Juli 2001
  • Laatst online: 09-05 09:52
Verwijderd schreef op 22 april 2004 @ 12:11:
dit staat erin:

(allemaal code)
Het lijkt erop of je je header en footer include, dit is natuurlijk niet te bedoeling...

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
sjoerdb schreef op 22 april 2004 @ 12:20:
[...]


Het lijkt erop of je je header en footer include, dit is natuurlijk niet te bedoeling...
precies, dat was het probleem :)


Ik ga die squirrelmail functie eens uitproberen
Pagina: 1