Jump to content

File viewing script


RLJ

Recommended Posts

Hi all,

 

This is probably a very basic question, but it's the first time I've had to deal with it and I can't find a direct answer anywhere online.

 

I have blocked direct access to a file that a user has uploaded in the Apache configuration and in the .htaccess file, so that the file is only accessible through a viewing (PHP) script, which will determine whether the access is allowed or not depending on several factors.

 

What is the actual code I need to give access?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/245953-file-viewing-script/
Share on other sites

Code as in "give me the code to do this"? I sure hope not.

 

The bare minimum is

1. Figure out what file the script is supposed to send

2. Make sure the file is okay to send (was uploaded, right file type, etc)

3. Figure out the type of file (JPEG image, PDF document, etc)

4.

header("Content-Type: $filetype"); // image/jpeg, application/pdf, etc
readfile($filename);

Link to comment
https://forums.phpfreaks.com/topic/245953-file-viewing-script/#findComment-1263331
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.