direct-downloadscript

Gesponsorde koppelingen

PHP script bestanden

  1. direct-downloadscript

« Lees de omschrijving en reacties

download.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
include("connection.php");
$downloadid=mysql_real_escape_string($_GET["id"]);
$query="SELECT * FROM ds_downloads WHERE id=$downloadid";
$uitvoeren=mysql_query($query);
$rij=mysql_fetch_assoc($uitvoeren);
$aantal=$rij["aantal"]+1;
mysql_query("UPDATE ds_downloads SET aantal=$aantal WHERE id=$downloadid");
            $filename = $rij["url"];
            $filename = realpath($filename);

            $file_extension = strtolower(substr(strrchr($filename,"."),1));

            switch ($file_extension) {
                case
"pdf": $ctype="application/pdf"; break;
                case
"exe": $ctype="application/octet-stream"; break;
                case
"zip": $ctype="application/zip"; break;
                case
"rar": $ctype="application/rar"; break;
                case
"wmv": $ctype="application/wmv"; 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
"bmp": $ctype="image/bmp"; break;
                case
"png": $ctype="image/png"; break;
                case
"jpe": case "jpeg":
                case
"jpg": $ctype="image/jpg"; break;
                default:
$ctype="application/force-download";
            }


            if (!file_exists($filename)) {
                die("Bestand niet gevonden.");
            }


            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private",false);
            header("Content-Type: $ctype");
            header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".@filesize($filename));
            set_time_limit(0);
            @
readfile("$filename") or die("Bestand is niet gevonden.");
?>


connection.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
mysql_connect('Host','User','Pass');
mysql_select_db('Database');
?>


Database
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
CREATE TABLE `ds_downloads` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `url` varchar(150) NOT NULL default '',
  `aantal` int(11) NOT NULL default '0',
  KEY `id` (`id`)
);

Dit is letterlijk het script dat ik gebruik. Je kan er elk script in uitvoeren wat je maar wilt.
Veel plezier!

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.