I have a rudimentary knowledge of PHP. I'm looking for a way to create a site that lists pdf fils that the user can click on and download. We use Joomla for our company intranet, but the component we are trying is not working and the forum for it has not helped.

I'm looking for an alternative - outside of Joomla.

TIA

jej1216

Dani AI

Generated

Quick follow-up to : uploading PDFs and linking to them is fine for a small intranet, but a tiny PHP pattern makes the list maintainable, lets you control access, and avoids accidental exposure.

Below is a minimal two‑file approach: a listing page that shows every PDF in a single folder, and a download script that validates the request, checks MIME type, and streams the file to the browser. Use basename, urlencode, and htmlspecialchars to avoid path traversal and XSS.

<?php
// list.php
$dir = __DIR__ . '/pdfs';
foreach (glob($dir . '/*.pdf') as $path) {
    $name = basename($path);
    echo '<a href="download.php?file=' . urlencode($name) . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . "</a><br>\n";
}
?>
<?php
// download.php
$dir = __DIR__ . '/pdfs';
$file = basename($_GET['file'] ?? '');
$path = $dir . '/' . $file;
if (!is_file($path)) { http_response_code(404); exit; }
$f = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($f, $path);
finfo_close($f);
if ($mime !== 'application/pdf') { http_response_code(403); exit; }
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . addslashes($file) . '"');
header('Content-Length: ' . filesize($path));
readfile($path);
?>

Notes and cautions: store sensitive files outside the web root and serve them through a script if access should be restricted. Validate uploaded files (size, extension, MIME) and never trust user input. For MIME checks see the PHP finfo_file docs and for forcing downloads see the Content-Disposition header details on MDN. For secure upload/storage practices consult the OWASP File Upload Cheat Sheet (OWASP File Upload Cheat Sheet, PHP finfo_file, Content-Disposition).

I got it - simply upload the doc and put a link to it. duh.

Thanks anyway.

jej1216

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.