source: admin/WebConsole/descargas/index.php

lgromero-new-oglive
Last change on this file was b6ec162, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#834: Remove all redundant PHP closing tags.

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[2a31d57]1<?php
[bd1a872]2// Warning: Don't left any character outside PHP code.
3//
4// Choose a file on this directory to download via Apache.
5
[2a31d57]6include_once("../includes/ctrlacc.php");
7include_once("../clases/AdoPhp.php");
8include_once("../includes/CreaComando.php");
[bd1a872]9include_once("../idiomas/php/".$idioma."/descargas_".$idioma.".php");
[2a31d57]10$cmd=CreaComando($cadenaconexion); // Crea objeto comando
11if (!$cmd)
[bd1a872]12        header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D.
[2a31d57]13
14// Security tip: change to local directory.
15$oldpwd=getcwd();
16chdir(dirname(__FILE__));
17if (isset($_POST['file'])) {
18        // Send file.
19        sendFile ($_POST['file']);
20} else {
[2a0be21]21        // Show list of files.
[2a31d57]22        echo '<!DOCTYPE html>'."\n";
23        echo '<html><head>'."\n";
24        echo '  <link rel="stylesheet" type="text/css" href="../estilos.css" />'."\n";
25        echo '</head><body>'."\n";
26        echo '<div align="center" class="tabla_datos">'."\n";
27        echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'."\n";
28        echo '  <table>'."\n";
29        echo '    <tr><th>'.$TbMsg['DOWNLOADS'].':</th></tr>'."\n";
30        $filelist = glob("*");
[2a0be21]31        $data = "";
[2a31d57]32        foreach ($filelist as $f) {
[2a0be21]33                // Get only readable files, except this one.
34                if ($f !== basename(__FILE__) and is_file($f) and is_readable($f)) {
35                        $data .= '      <option value="'.$f.'">'.$f.'</option>'."\n";
36                }
37        }
38        if (empty($data)) {
39                // Show warning message if there is no files to download.
40                echo '    <tr><td>'.$TbMsg['NOFILES'].'</td></tr>'."\n";
41        } else {
42                // Show available files.
43                echo '    <tr><td><select name="file">'."\n";
44                echo $data;
45                echo '      </select>'."\n";
46                echo '      <input type="submit" value="" style="width:20px; background:url(../images/boton_confirmar.gif);"></td></tr>'."\n";
[2a31d57]47        }
48        echo '</table>'."\n";
49        echo '</form>'."\n";
50        echo '</body></html>'."\n";
51}
52// Change again to source directory.
53chdir($oldpwd);
54
55
56// Send a file.
57function sendFile($file) {
58        // Check if file exists in current directory and it isn't this file.
59        if (file_exists($file) and strpos($file,"/") === false and $file !== basename(__FILE__)) {
[b9bdfa0]60                header('Content-Type: ' . mime_content_type($file));
[2a31d57]61                header('Content-Length: ' . filesize($file));
62                header('Content-Disposition: attachment; filename="' . $file . '"');
[b9bdfa0]63                readfile($file);
[2a31d57]64        }
65}
66
[bd1a872]67// Warning: Don't left any character outside PHP code.
[b6ec162]68
Note: See TracBrowser for help on using the repository browser.