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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.