Uploading and viewing.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cle13
Forum Newbie
Posts: 3
Joined: Thu Aug 03, 2006 6:52 am

Uploading and viewing.

Post by cle13 »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. Send the proper header(): application/pdf, content-length, probably encoding
  2. use readfile()
That's about it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

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:

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);
That's not tested, obviously. Read up on this:

Code: Select all

header()
And this:

http://us3.php.net/readfile
Post Reply