Scripts
Up/Download Script met Statistieken
Mijn simpele Up/Download script. Wat zit erin? - Upload script van Paradox™ - Download script met aftellen - Statistieken (id,filenaam,aantal downloads) - Verwijderen (file en stats in db)
updownload-script-met-statistieken
Mysql Database:
[code]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 ;[/code]
Index.php:
[code]<?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 geüpload.<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 } ?>[/code]
Config.php:
[code]<?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>";
?>[/code]
Stats.php:
<?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
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>[/code]
Delete.php:
[code]<?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">';
?>[/code]
Maak de map "files" aan!
EDIT:
- Extensie probleem gefixed
- Controle mysql_query gefixed
- $newname gefixed
- Copyrights gefixed
Reacties
0