Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- DROP TABLE IF EXISTS `descargas`;
- CREATE TABLE `descargas` (
- `ruta` varchar(200) NOT NULL,
- `descargas` int(10) unsigned NOT NULL,
- PRIMARY KEY (`ruta`)
- );
- */
- $carpeta = '/ruta/a/las/descargas/';
- $hostname = 'localhost';
- $username = 'root';
- $password = '';
- $database = 'test';
- $archivo = basename(isset($_GET['archivo']) ? $_GET['archivo'] : '');
- $ruta = $carpeta . $archivo;
- if (file_exists($ruta)) {
- $db = new MySQLi($hostname, $username, $password, $database);
- if ($db->connect_error) {
- die("Error de conexión ({$mysqli->connect_errno}): {$mysqli->connect_error}.");
- }
- $result = $db->query("insert into descargas (ruta, descargas) values
- ('" . $db->escape_string($ruta) . "', 1) on duplicate key update descargas = descargas + 1");
- if (false === $result) {
- die("Error ({$db->errno}): {$db->error}.");
- }
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Cache-Control: private');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=' . $archivo);
- header('Content-Transfer-Encoding: binary');
- header('Content-Length: ' . filesize($ruta));
- readfile($ruta);
- } else {
- echo "El archivo <b>$archivo</b> no existe. Notifíquelo al webmaster. Gracias";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement