buongiorno non capisco il perchè non scarica il pdf ma lo apre e si vedono dei caratteri strani sono riuscito a rendere visibile a ogni utente la sua cartella ho fatto cosi chiedo aiuto grazie
Codice:
<?PHP
// Define a function to list files and subfolders
function list_files($dir) {
// Get an array of files and subfolders
$files = scandir($dir);
// Loop through the array
foreach ($files as $file) {
// Skip the current and parent directories
if ($file != "." && $file != "..") {
// Get the full path of the file or folder
$path = $dir . "/" . $file;
// Check if it is a file
if (is_file($path)) {
// Get the file name
$name = basename($path);
// Encode the file path
$url = urlencode($path);
// Create a download link
echo "Documento: <a href='download.php?file=$url'>$name</a><br>";
}
// Check if it is a folder
if (is_dir($path)) {
// Print the folder name
echo "Cartella: <b>$file</b>";
// Call the function recursively
list_files($path);
}
}
}
}
// Call the function with the main directory
list_files("documenti/".basename($_SESSION['username']));
?>
-------------------------
DOWNLOAD
<?php
if(isset($_GET['file'])){
$var_1 = $_GET['file'];
$dir='documenti/';
}
?>
<?php
if(isset($_GET['file'])){
$var_1 = $_GET['file'];
$file = $var_1;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
echo "<h1>Content error</h1><p>il file non esiste!</p>";
}
?>