/* ============================================ OPEN BESTAND (in browser) ============================================ */ if (isset($_GET['open']) && !empty($perms['read'])) { $openRel = ltrim($_GET['open'], '/\\'); $openRel = normalize_path($openRel); $openFull = normalize_path($rootPath . DS . $openRel); $openFullReal = realpath($openFull); if ($openFullReal && ensure_within_root($openFullReal) && is_file($openFullReal)) { fm_log($user." open: ".$openFullReal); $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $openFullReal); finfo_close($finfo); header("Content-Type: ".$mime); header("Content-Length: " . filesize($openFullReal)); header("Content-Disposition: inline; filename=\"".basename($openFullReal)."\""); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); if (ob_get_level()) ob_end_clean(); readfile($openFullReal); exit; } } /* ============================================ DOWNLOAD VIA GET (grote bestanden ondersteund) ============================================ */ if (isset($_GET['download']) && !empty($perms['read'])) { $dlRel = ltrim($_GET['download'], '/\\'); $dlRel = normalize_path($dlRel); $dlFull = normalize_path($rootPath . DS . $dlRel); $dlFullReal = realpath($dlFull); /* Validatie vóór headers */ if (!$dlFullReal) { fm_error("Het bestand bestaat niet."); } if (!ensure_within_root($dlFullReal)) { fm_error("Ongeldige bestandslocatie."); } if (!is_file($dlFullReal)) { fm_error("Dit is geen geldig bestand om te downloaden."); } /* Log */ fm_log($user . " download: " . $dlFullReal); /* Headers voor download */ header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . basename($dlFullReal) . "\""); header("Content-Length: " . filesize($dlFullReal)); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); /* Output buffer legen */ if (ob_get_level()) { ob_end_clean(); } /* Bestand streamen in chunks */ $fp = fopen($dlFullReal, 'rb'); if ($fp === false) { fm_error("Kan bestand niet openen."); } $chunkSize = 1024 * 1024; // 1MB while (!feof($fp)) { echo fread($fp, $chunkSize); flush(); } fclose($fp); exit; } /* ============================================ EDIT VIEW (GET) ============================================ */ if (isset($_GET['edit']) && !empty($perms['edit'])) { $editRel = ltrim($_GET['edit'], '/\\'); $editRel = normalize_path($editRel); $editFull = normalize_path($rootPath . DS . $editRel); $editFullReal = realpath($editFull); /* Bestaat het bestand? */ if (!$editFullReal) { fm_error("Het geselecteerde bestand bestaat niet."); } /* Binnen root? */ if (!ensure_within_root($editFullReal)) { fm_error("Ongeldige bestandslocatie."); } /* Is het een bestand? */ if (!is_file($editFullReal)) { fm_error("Dit item kan niet worden bewerkt."); } /* Groottecontrole */ $size = filesize($editFullReal); if ($size > $MAX_EDIT_BYTES) { fm_error("Bestand is te groot om te bewerken."); } /* Inhoud ophalen */ $content = file_get_contents($editFullReal); if ($content === false) { fm_error("Het bestand kon niet worden geopend."); } /* Binaire bestanden blokkeren */ if (is_binary_string($content)) { fm_error("Dit bestand kan niet als tekst worden bewerkt."); } $openRel = str_replace('\\', '/', $relPath); ?> Web File Manager - Bewerken