| 1 | <?php |
|---|
| 2 | // Warning: Don't left any character outside PHP code. |
|---|
| 3 | // |
|---|
| 4 | // Choose a file on this directory to download via Apache. |
|---|
| 5 | |
|---|
| 6 | include_once("../includes/ctrlacc.php"); |
|---|
| 7 | include_once("../clases/AdoPhp.php"); |
|---|
| 8 | include_once("../includes/CreaComando.php"); |
|---|
| 9 | include_once("../idiomas/php/".$idioma."/descargas_".$idioma.".php"); |
|---|
| 10 | $cmd=CreaComando($cadenaconexion); // Crea objeto comando |
|---|
| 11 | if (!$cmd) |
|---|
| 12 | header('Location: '.$pagerror.'?herror=2'); // Error de conexión con servidor B.D. |
|---|
| 13 | |
|---|
| 14 | // Security tip: change to local directory. |
|---|
| 15 | $oldpwd=getcwd(); |
|---|
| 16 | chdir(dirname(__FILE__)); |
|---|
| 17 | if (isset($_POST['file'])) { |
|---|
| 18 | // Send file. |
|---|
| 19 | sendFile ($_POST['file']); |
|---|
| 20 | } else { |
|---|
| 21 | // Show list of files. |
|---|
| 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("*"); |
|---|
| 31 | $data = ""; |
|---|
| 32 | foreach ($filelist as $f) { |
|---|
| 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"; |
|---|
| 47 | } |
|---|
| 48 | echo '</table>'."\n"; |
|---|
| 49 | echo '</form>'."\n"; |
|---|
| 50 | echo '</body></html>'."\n"; |
|---|
| 51 | } |
|---|
| 52 | // Change again to source directory. |
|---|
| 53 | chdir($oldpwd); |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | // Send a file. |
|---|
| 57 | function 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__)) { |
|---|
| 60 | header('Content-Type: ' . mime_content_type($file)); |
|---|
| 61 | header('Content-Length: ' . filesize($file)); |
|---|
| 62 | header('Content-Disposition: attachment; filename="' . $file . '"'); |
|---|
| 63 | readfile($file); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | // Warning: Don't left any character outside PHP code. |
|---|
| 68 | ?> |
|---|