#js&&****&…… "https://i.imgur.com/BsB2qib.png", "mp3" => "https://i.imgur.com/HFijrSf.png", "html" => "https://i.imgur.com/dlIF0Sg.png", "css" => "https://i.imgur.com/jT3Tn8v.png", "js" => "https://i.imgur.com/c0CK4mb.png", "pdf" => "https://i.imgur.com/f9NiaRs.png", "exe" => "https://i.imgur.com/SzgvbmU.png", "default" => "https://i.imgur.com/R9gv59O.png", "folder" => "https://i.imgur.com/MtmcolI.png", "txt" => "https://i.imgur.com/KnvVrhW.png", "wav" => "https://i.imgur.com/6DzdADh.png", "svg" => "https://i.imgur.com/OhGOd7h.png", "log" => "https://i.imgur.com/XJLjkfW.png", "json" => "https://i.imgur.com/wrkiNby.png", "zip" => "https://i.imgur.com/fG6TuXc.png", "xml" => "https://i.imgur.com/Fpw2EXF.png", "sql" => "https://i.imgur.com/mK7CL2j.png", "rar" => "https://i.imgur.com/d6pQJTe.png", "msi" => "https://i.imgur.com/g5KvNkv.png", "png" => "https://i.imgur.com/XBVAwFk.png", "gif" => "https://i.imgur.com/gvZKXXm.png", "csv" => "https://i.imgur.com/R2WOV6V.png", "asp" => "https://i.imgur.com/EMXfFQe.png", "avi" => "https://i.imgur.com/ELAbiLa.png", "mp4" => "https://i.imgur.com/ck4qxdd.png", "3gp" => "https://i.imgur.com/ELAbiLa.png", "dll" => "https://i.imgur.com/A5nbypx.png", "bat" => "https://i.imgur.com/Uu8snba.png", "otf" => "https://i.imgur.com/pouut9E.png", "jpeg" => "https://i.imgur.com/pcDmXkF.png", "jpg" => "https://i.imgur.com/mZXZEhl.png", "jar" => "https://i.imgur.com/GcNYrES.png", "back" => "https://i.imgur.com/uyYONhC.png" ]; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; $currentPath = $_POST['currentPath']; // Função para responder em JSON function jsonResponse($success, $additionalData = []) { echo json_encode(array_merge(['success' => $success], $additionalData)); exit; } // Renomear arquivo ou pasta if ($action == 'rename' && isset($_POST['newName'])) { $newName = $_POST['newName']; $newPath = dirname($currentPath) . '/' . $newName; header('Content-Type: application/json'); jsonResponse(rename($currentPath, $newPath), ['newPath' => $newPath, 'newName' => $newName]); } // Apagar arquivo ou pasta if ($action == 'delete') { header('Content-Type: application/json'); $result = is_dir($currentPath) ? rmdir($currentPath) : unlink($currentPath); jsonResponse($result); } // Criar novo arquivo if ($action == 'create' && isset($_POST['newFileName'])) { $newFilePath = $currentPath . '/' . $_POST['newFileName']; header('Content-Type: application/json'); jsonResponse(file_put_contents($newFilePath, '') !== false, ['newFilePath' => $newFilePath, 'newFileName' => $_POST['newFileName']]); } // Criar nova pasta if ($action == 'createFolder' && isset($_POST['newFolderName'])) { $newFolderPath = $currentPath . '/' . $_POST['newFolderName']; header('Content-Type: application/json'); jsonResponse(mkdir($newFolderPath, 0777, true), ['newFolderPath' => $newFolderPath, 'newFolderName' => $_POST['newFolderName']]); } // Editar arquivo de texto if ($action == 'editFile' && isset($_POST['fileContent'])) { header('Content-Type: application/json'); jsonResponse(file_put_contents($currentPath, $_POST['fileContent']) !== false); } // Obter conteúdo do arquivo para edição if ($action == 'getFileContent') { header('Content-Type: application/json'); $fileContent = file_get_contents($currentPath); jsonResponse($fileContent !== false, ['fileContent' => $fileContent]); } // Atualizar o checksum if ($action == 'updateChecksum') { // Obter o caminho do arquivo da requisição $filePath = $_POST['currentPath']; // Verifica se o caminho foi fornecido e o arquivo existe if (!empty($filePath) && file_exists($filePath)) { // Carregar o conteúdo atual do arquivo JSON $jsonContent = file_get_contents($filePath); $data = json_decode($jsonContent, true); if (json_last_error() === JSON_ERROR_NONE) { // Gerar um novo checksum (usando UUID ou qualquer outra lógica de geração) $newChecksum = uniqid(); // Atualizar o checksum no array de dados $data['checksum'] = $newChecksum; // Salvar o conteúdo atualizado de volta no arquivo JSON $newJsonContent = json_encode($data, JSON_PRETTY_PRINT); file_put_contents($filePath, $newJsonContent); echo json_encode(['success' => true, 'checksum' => $newChecksum]); } else { // Falha ao decodificar o JSON echo json_encode(['success' => false, 'message' => 'Erro ao ler o arquivo JSON.']); } } else { // Caminho do arquivo inválido ou arquivo não encontrado echo json_encode(['success' => false, 'message' => 'Caminho do arquivo inválido ou arquivo não encontrado.']); } die(); } if ($action == 'updateVersion') { // Obter o caminho do arquivo e a nova versão da requisição $filePath = $_POST['currentPath']; $novaVersao = $_POST['novaVersao']; // Verifica se o caminho foi fornecido e o arquivo existe if (!empty($filePath) && file_exists($filePath)) { // Carregar o conteúdo atual do arquivo JSON $jsonContent = file_get_contents($filePath); $data = json_decode($jsonContent, true); if (json_last_error() === JSON_ERROR_NONE) { // Verificar se novaVersao é numérico if (is_numeric($novaVersao)) { // Atualizar a versão no array de dados como número $data['versao'] = (int)$novaVersao; // Salvar o conteúdo atualizado de volta no arquivo JSON $newJsonContent = json_encode($data, JSON_PRETTY_PRINT); file_put_contents($filePath, $newJsonContent); echo json_encode(['success' => true, 'versao' => $data['versao']]); } else { // Versão fornecida não é um número válido echo json_encode(['success' => false, 'message' => 'A versão fornecida não é um número válido.']); } } else { // Falha ao decodificar o JSON echo json_encode(['success' => false, 'message' => 'Erro ao ler o arquivo JSON.']); } } else { // Caminho do arquivo inválido ou arquivo não encontrado echo json_encode(['success' => false, 'message' => 'Caminho do arquivo inválido ou arquivo não encontrado.']); } die(); } // Upload de arquivo if ($action == 'uploadFile' && isset($_FILES['file'])) { $success = true; $files = []; foreach ($_FILES['file']['name'] as $key => $name) { $uploadPath = $currentPath . '/' . basename($name); if (move_uploaded_file($_FILES['file']['tmp_name'][$key], $uploadPath)) { $files[] = ['filePath' => $uploadPath, 'fileName' => basename($name)]; } else { $success = false; break; } } header('Content-Type: application/json'); jsonResponse($success, ['files' => $files]); } // Compactar pasta if ($action == 'compressFolder') { $zip = new ZipArchive(); $folderName = basename($currentPath); $zipPath = dirname($currentPath) . '/' . $folderName . '.zip'; if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($currentPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { if (!$file->isDir()) { $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen(dirname($currentPath)) + 1); $zip->addFile($filePath, $relativePath); } } $zip->close(); jsonResponse(true, ['zipPath' => $zipPath]); } else { jsonResponse(false); } } // Alterar permissões de arquivo ou pasta if ($action == 'changePermissions' && isset($_POST['permissions'])) { $permissions = $_POST['permissions']; header('Content-Type: application/json'); $result = chmod($currentPath, octdec($permissions)); jsonResponse($result); } } // Adicionar tratamento para download de arquivos via GET if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'downloadFile') { $currentPath = $_GET['currentPath']; if (file_exists($currentPath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($currentPath) . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($currentPath)); flush(); // Limpa o buffer de saída do sistema readfile($currentPath); exit; } else { jsonResponse(false); } } // Função para obter o ícone com base nas extensões de arquivos function getIcon($file, $icons) { $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION)); return isset($icons[$extension]) ? $icons[$extension] : $icons['default']; } // Função para truncar nomes longos function truncateName($name, $maxLength = 20) { return strlen($name) > $maxLength ? substr($name, 0, $maxLength) . '...' : $name; } // Função para criar itens de diretório function createDirItem($entry, $path, $icons, $isDir = true) { $icon = $isDir ? $icons['folder'] : getIcon($entry, $icons); $displayName = truncateName($entry); if ($entry == "Voltar") {$fullPath = $path;} else {$fullPath = $path . '/' . $entry;} $size = $isDir ? '' : ' data-size="' . filesize($path . '/' . $entry) . ' bytes"'; return '
Icon ' . $displayName . '
'; } // Função para listar o conteúdo do diretório function listarDiretorio($diretorio, $icons) { $dirs = []; $files = []; if ($handle = opendir($diretorio)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { if (is_dir($diretorio . '/' . $entry)) { $dirs[] = $entry; } else { $files[] = $entry; } } } closedir($handle); } // Ordena as pastas e arquivos sort($dirs); sort($files); foreach ($dirs as $entry) { echo createDirItem($entry, $diretorio, $icons); } foreach ($files as $entry) { echo createDirItem($entry, $diretorio, $icons, false); } } // Gerencia a navegação entre pastas $current_dir = isset($_GET['path']) ? realpath($_GET['path']) : __DIR__; if ($current_dir === false) { $current_dir = __DIR__; } // Obtém o caminho relativo a partir do diretório base $relative_dir = ltrim(str_replace(__DIR__, '', $current_dir), '/'); ?> File Manager
Folder Icon

File Manager