updownload-script-met-statistieken

Gesponsorde koppelingen

PHP script bestanden

  1. updownload-script-met-statistieken

« Lees de omschrijving en reacties

Mysql Database:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
CREATE TABLE `stats` (
`id` int(255) NOT NULL auto_increment,
`file` text NOT NULL,
`downloads` varchar(255) NOT NULL default '0',
PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Index.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
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
<?php
////////////////////////////////////
// © 2009 Wouter De Schuyter
// info[@]paradox-productions[.]net
// http://paradox-productions.net/
// UPLOAD SCRIPT V1.0
////////////////////////////////////

/* NOTE
*******
!! DON'T FORGET TO CHMOD THE UPLOAD FOLDER TO 0777

THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE.
THIS MEANS YOU MAY USE IT FOR ANY PURPOSE, AND MAKE ANY CHANGES YOU LIKE.
ALL I ASK IS TO LEAVE THE ORIGINAL COPYRIGHT AT TOP OF THE SCRIPT.
VIEW LICENSE ONLINE: http://creativecommons.org/licenses/by/3.0/
*/


include "config.php";
$extensions = array('png', 'gif', 'jpg', 'jpeg', 'bmp', 'pdf', 'doc', 'docx', 'html', 'psd', 'css', 'zip', 'rar', '7z'); //bestandsformaten
$tfolder = "files/"; // bestandsmap
$scriptloc = "http://JESITE/projects/upload/"; //volledige url
$maxfsize = 125; //max mb per file

if($_SERVER['REQUEST_METHOD'] == "POST") {
    $fname = $_FILES['filen']['name'];
    $fext = strtolower(end(explode('.', $fname)));
    $ftemp = $_FILES['filen']['tmp_name'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $random = rand(1, 5000000);
    $newname = md5(time() . $ip . $random . $fext);
    $target = $tfolder . $newname;
        
if(!empty($fname)) {
    foreach($extensions as $check) {
        if($check == $fext) {
            $extensioncheck = true;
        }
}


if($extensioncheck == true) {
    if(filesize($ftemp) > $maxfsize * (1024*1024)) {
        $fout = "Uw bestand is te groot. De maximale bestandsgrootte is <b>" . $maxfsize . "</b>MB.";
    }
else {
        if(!strstr(strtolower($fname), "php")) {
            $upload = move_uploaded_file($ftemp, $target);
            $downloadurl = "$scriptloc" . "download.php?file=$newname";
            $statsurl = "$scriptloc" . "stats.php?file=$newname";
            $deleteurl = "$scriptloc" . "delete.php?file=$newname";
        if($upload) {
            mysql_query ("INSERT INTO stats VALUES ('','$newname','0')") or die(mysql_error());
            $succes = true;
    }
else {
        $fout = "Uploadfout! Als het oploaden mislukt, zet alles dan in een zip/rar/7z file, en probeer het opnieuw!";
    }}
else {
        $fout = "Uw bestand mag niet de tekst 'php' bevatten!";
    }}}
else {
        $fout = "Dit bestandsformaat is niet toegestaan!";
    }}
else {
        $fout = "Selecteer een bestand om te uploaden.";
    }
}


if($succes !== true) {
    echo '<b>De maximale bestandsgroote is ' . $maxfsize . 'MB.</b>';
    echo '<form action="" method="post" enctype="multipart/form-data">';
    echo '<input type="file" name="filen" /><input type="submit" name="subform" value="Uploaden" />';
    echo '</form>';
    echo $fout;
}

?>


<?php if ($upload) { ?>

Uw bestand is succesvol gepload.<br />
Download link: <b><a href="<?php echo "$downloadurl"; ?>"><?php echo "$downloadurl"; ?></a></b><br />
Statistieken: <b><a href="<?php echo "$statsurl"; ?>"><?php echo "$statsurl"; ?></a></b><br />
Bestand verwijderen: <b><a href="<?php echo "$deleteurl"; ?>"><?php echo "$deleteurl"; ?></a></b>

<?php } ?>


Config.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
<?php
error_reporting(0);
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$database=""; // Database name

$connect = mysql_connect("$host", "$username", "$password")or die("Fout in de database!");
$select = mysql_select_db("$database")or die("Fout in de database!");
$file = $_GET['file'];
echo "<link rel='shortcut icon' href='favicon.png' />";
echo "<title>Upload Script 1.0</title>";
?>


Stats.php:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
include "config.php";

$sql = "SELECT * FROM stats WHERE file = '$file'";
$res = mysql_query($sql);

while ($row = mysql_fetch_array($res)) {
    echo "Bestands ID: $row[id]<br />";
    echo "Bestandsnaam: $row[file]<br />";
    echo "Aantal keren gedownload: $row[downloads]";
}

?>


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
<?php
include "config.php";
if (file_exists("files/$file")) {
    mysql_query ("UPDATE stats SET downloads = downloads + '1' WHERE file = '$file'") or die(mysql_error()); //stats in db zetten
    echo "<b>Uw download begint over 25 seconden!</b>";
}
else {
    die('<b>Helaas is de door u geselecteerde link niet beschikbaar.</b><title>Download</title>'); //file is niet meer
}
?>

<html>
<head>
<meta http-equiv="refresh" content="30">
<style type="text/css">
#countdown {
color: #f90;
font-family: Verdana;
font-weight: bold;
font-size: 240px;
line-height: 100%;
float: right;
}
</style>
<script language="JavaScript">
<!--
var timer = 25; //aantal seconden wachten
function aftel() {
document.getElementById('countdown').innerHTML = timer;
timer--;
if (timer >= 0) {
setTimeout('aftel()',1000);
} else {
document.location = "files/<?php echo "$file"; ?>";
};
};
//-->
</script>
</head>
<body onLoad="aftel()">
<span id="countdown">#</span>
</body>
</html>


Delete.php:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<?php
include "config.php";
unlink("files/$file");
mysql_query ("DELETE FROM stats WHERE file = '$file'") or die(mysql_error());
echo "<b>Het bestand is succesvol verwijderd!</b>";
echo '<meta http-equiv="refresh" content="4;url=index.php">';
?>


Maak de map "files" aan!

EDIT:
- Extensie probleem gefixed
- Controle mysql_query gefixed
- $newname gefixed
- Copyrights gefixed

 
 

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.