Problem med fildownload, hentes 2 gange?
HejJeg har nedenstående script til at
1. Downloade filer uden at brugeren får stien til filen at vide
2. Tælle antal downloads
Problemet er at når jeg henter filen tælles der op 2-3 gange i min download tabel. I Firefox har jeg med "Live HTTTP headers" udvidelsen fået syn for sagen, det ser faktisk ud som om min fil hentes flere gange:
http://localhost/cm3/index.php?pid=34
GET /cm3/index.php?pid=34 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; da; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/cm3/
Cookie: PHPSESSID=6523b64fb3c448c794e768a403ba1fd7
Range: bytes=0-
If-Range: "e369853df766fa44e1ed0ff613f563bd"
HTTP/1.x 200 OK
Date: Thu, 12 Jul 2007 10:10:45 GMT
Server: Apache/2.2.4 (Win32) PHP/5.2.1
X-Powered-By: PHP/5.2.1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: must-revalidate, post-check=0, pre-check=0, private
Pragma: public
Etag: "e369853df766fa44e1ed0ff613f563bd"
Accept-Ranges: bytes
Content-Length: 316667
content-disposition: inline; filename="emu_saa_kan_du_laere_det_plakat.pdf";
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/pdf
----------------------------------------------------------
http://localhost/cm3/index.php?pid=34
GET /cm3/index.php?pid=34 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; da; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/cm3/index.php?pid=34
Cookie: PHPSESSID=6523b64fb3c448c794e768a403ba1fd7
Pragma: no-cache
Cache-Control: no-cache
HTTP/1.x 200 OK
Date: Thu, 12 Jul 2007 10:10:46 GMT
Server: Apache/2.2.4 (Win32) PHP/5.2.1
X-Powered-By: PHP/5.2.1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: must-revalidate, post-check=0, pre-check=0, private
Pragma: public
Etag: "e369853df766fa44e1ed0ff613f563bd"
Accept-Ranges: bytes
Content-Length: 316667
content-disposition: inline; filename="emu_saa_kan_du_laere_det_plakat.pdf";
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/pdf
----------------------------------------------------------
Nåh...herunder en del af mit script:
$sql_upd = 'UPDATE ' . $prefix . '_filer set antal_downloads=antal_downloads+1 WHERE fil="filarkiv/' . $row_indhold['fil'] . '"';
$result_upd = mysql_query($sql_upd) or die(mysql_error());
$taeller_upd++;
switch($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("ETag: \"" . md5($_REQUEST['pid']) . "\"");
header("Accept-Ranges: bytes");
header("Content-Length: ".filesize($filename));
//header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
//change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: inline; filename=\"".basename($filename)."\";" );
//header("Content-Transfer-Encoding: binary\n");
readfile("$filename");
exit();
Er der nogen der kan hjælpe?
