I want to allow registered members to upload files to the file system

I have two mysql tables members for registered users and a table files to have a trace which member uploaded which file.

now, I only would like to allow the upload of PDF's to the file system.

Then, I want the users to be able to leave a comment about what they think about the uploaded file and maybe even give a rating.

But for that my question is: What would be the easiest way to display the PDF's on a website to be able to allow other users to add a comment ?

currently, the PDF's would just be stored in a folder on the file system. How to get them displayed in a web page??

for information, my files table has
file_id primary key auto_increment
username (same as the username in the members table)
Time
type (MIME)
Size
IP (of user)
notes (folder name)
other text fields about the file like subject which should be searchable with a tag related search

Dani AI

Generated

As hinted, you can absolutely have the uploaded PDF appear in a viewer page automatically — it does not need to be a manual step. The usual, robust approach is: (1) accept and validate the upload server‑side, (2) record the stored filename and metadata in your DB, (3) either redirect the user to a viewer URL (example: view.php?file_id=123) or return the viewer URL/ID from the upload handler and set the viewer element on the page via JavaScript. That lets you show the PDF and the comments/rating UI together without extra manual linking.

A minimal safe server flow is: validate MIME/content (finfo + check the file starts with “%PDF-”), move the file to a non‑public folder with a unique stored name, insert the metadata in the DB, then serve the file through a script that enforces access control and sets PDF headers. Example serve script sketch:

// serve.php?id=123
$id = intval($_GET['id'] ?? 0);
// fetch $row from DB for $id and check permissions...
$path = '/var/uploads/' . $row['stored_name'];
if(!file_exists($path)){ http_response_code(404); exit; }
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="'.basename($row['original_name']).'"');
readfile($path);
exit;

For an AJAX upload that updates the viewer without reloading:

fetch('/upload.php', { method:'POST', body: formData })
  .then(r => r.json())
  .then(j => { if(j.ok) document.getElementById('pdfFrame').src = '/serve.php?id='+j.id; });

Security and UX notes: never trust the extension alone, limit file size, scan uploads if possible, store outside webroot and serve via script, disable script execution in upload folders, use prepared statements for DB writes, escape user comments on output, use CSRF tokens, and prevent duplicate voting for ratings. For consistent in‑page rendering (especially on mobile) consider using a client viewer like PDF.js as a fallback so users don’t get sent to external apps.

Recommended Answers

All 2 Replies

If I understand you correctly you want to be able to display a PDF on screen in a browser and have a user enter comments. The first part is easy, browsers display PDFs naturally so you just link to the PDF. To have the PDF and the ratings/comments section on screen at the same time link the PDF to an iFrame and have the comments below it (or above it). Then you can have both things on the one page and easily viewed by the user.

commented: thx, I'll give it a try +0

Hello, this is correct. I have just one more question. Do you know if it would be possible to automatically link the PDF to the iFrame when doing the upload of the PDF to the file system? Or can it only be done manually after the upload has been done?

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.