Page 1 of 1

Uploading and viewing.

Posted: Thu Aug 17, 2006 12:07 am
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.

Posted: Thu Aug 17, 2006 12:29 am
by feyd
  1. Send the proper header(): application/pdf, content-length, probably encoding
  2. use readfile()
That's about it.

Posted: Thu Aug 17, 2006 12:33 am
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