Select a drawing to view
No Drawing Selected
Select a PDF file from the sidebar to view it here. The viewer prevents direct downloading via standard UI elements.
isFile() && strtolower($file->getExtension()) === 'pdf') { $filename = $file->getFilename(); if (strpos(strtolower($filename), $query) !== false) { $filePath = $file->getPathname(); $relativePath = ltrim(str_replace($realBaseDir, '', $filePath), DIRECTORY_SEPARATOR); $relativePath = str_replace('\\', '/', $relativePath); // Normalize slashes $folderPath = dirname($relativePath); if ($folderPath === '.') $folderPath = 'Root Directory'; $items[] = [ 'name' => $filename, 'path' => $relativePath, 'url' => 'drawing/' . str_replace('#', '%23', $relativePath), 'type' => 'file', 'folder' => $folderPath, 'size' => @filesize($filePath) ?: 0, 'date' => @filemtime($filePath) ?: 0 ]; } } } } // Default Sort alphabetically usort($items, function($a, $b) { return strcasecmp($a['name'], $b['name']); }); echo json_encode([ 'success' => true, 'items' => $items, 'currentPath' => 'Search Results' ]); exit; } // 2. DIRECTORY LISTING ENDPOINT if (isset($_GET['api']) && $_GET['api'] === 'list') { header('Content-Type: application/json'); // Define the base directory for drawings $baseDir = __DIR__ . DIRECTORY_SEPARATOR . 'drawing'; // Auto-create the drawing folder if it doesn't exist if (!file_exists($baseDir)) { mkdir($baseDir, 0755, true); } $requestPath = isset($_GET['path']) ? $_GET['path'] : ''; // Security: Prevent directory traversal attacks $requestPath = str_replace(['../', '..\\'], '', $requestPath); $targetDir = realpath($baseDir . DIRECTORY_SEPARATOR . $requestPath); $realBaseDir = realpath($baseDir); // Security: Ensure target directory is strictly inside the base directory if ($targetDir === false || strpos($targetDir, $realBaseDir) !== 0 || !is_dir($targetDir)) { echo json_encode(['success' => false, 'error' => 'Invalid directory path.']); exit; } $items = []; $files = scandir($targetDir); foreach ($files as $file) { if ($file === '.' || $file === '..') continue; $filePath = $targetDir . DIRECTORY_SEPARATOR . $file; $relativePath = ltrim(str_replace($realBaseDir, '', $filePath), DIRECTORY_SEPARATOR); $relativePath = str_replace('\\', '/', $relativePath); // Normalize slashes for web if (is_dir($filePath)) { $items[] = [ 'name' => $file, 'path' => $relativePath . '/', 'type' => 'folder', 'size' => 0, 'date' => @filemtime($filePath) ?: 0 ]; } else if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'pdf') { $items[] = [ 'name' => $file, 'path' => $relativePath, 'url' => 'drawing/' . str_replace('#', '%23', $relativePath), // Encode # for URL 'type' => 'file', 'size' => @filesize($filePath) ?: 0, 'date' => @filemtime($filePath) ?: 0 ]; } } // Sort array: Folders first, then alphabetically (Default) usort($items, function($a, $b) { if ($a['type'] === $b['type']) return strcasecmp($a['name'], $b['name']); return $a['type'] === 'folder' ? -1 : 1; }); echo json_encode([ 'success' => true, 'items' => $items, // Return cleaned current path for breadcrumbs 'currentPath' => str_replace('\\', '/', ltrim(str_replace($realBaseDir, '', $targetDir), DIRECTORY_SEPARATOR)) ]); exit; } ?>
Select a PDF file from the sidebar to view it here. The viewer prevents direct downloading via standard UI elements.