Uploading and viewing.
Moderator: General Moderators
Uploading and viewing.
Hello people, I have a problem. I have a site where I use php to upload files (documents) and Im supposed to view the documents I have uploaded. I can upload any type of document but I would like to only upload .pdf documents and also be ableto view them(which I've failed to do currently). Can anyone help me with code that I can use to view an uploaded document? Thanx.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
- Send the proper header(): application/pdf, content-length, probably encoding
- use readfile()
if you're just looking for the ablity to view the documents, you can either store them under the root directory and then link to the file directly, or you can force the user to download it with something like this:
That's not tested, obviously. Read up on this:
And this:
http://us3.php.net/readfile
Code: Select all
header("Content-Type: ".get_mimetype($file));
header("Content-Length: ".filesize($full_path_to_file));
header("Content-Disposition: attachment; filename=$file");
readfile($full_path_to_file);Code: Select all
header()http://us3.php.net/readfile