Secure folder public_html

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
chaitenya123
Forum Newbie
Posts: 2
Joined: Mon Apr 09, 2007 2:58 am

Secure folder public_html

Post by chaitenya123 »

hi,

friends i m facing a problem. Actually friends as you know on the server we put all the files into public_html folder which is directly accessible to the world, here i want to put some image file out side the public_html folder and want to display that images on the web page sothat people can see the images but they can not download the images.
Its all about security reason.
Plz give me any solution or suggestion

Very very thanks
Chaitenya yadav
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If you want them to see the file, they'll need to download it (so their computer can render it)...

You can disallow direct access to the files.. and only let them download the images via a 'controller' script, eg:

Code: Select all

<?php

// check if the user has been logged in, still has enough credits, ...

if (isset($_GET['file']))
{
 $real_path = $required_base_path . '/' . real_path($_GET['file']);

 $required_base_path = '/home/user/somethingprivate';

 if (substr($real_path, 0, strlen($required_base_path)) == $required_base_path)
 {
  $size = filesize($real_path);
  $content = mime_content_type($real_path);
  $name = basename($real_path);

  header("Content-length: $size");
  header("Content-Type: $content");
  readfile($real_path);
 }
}
chaitenya123
Forum Newbie
Posts: 2
Joined: Mon Apr 09, 2007 2:58 am

Post by chaitenya123 »

hi timvw,

very very thanks for your valuable words but dear my requirement is that i have to display images/swf file on web page but

i want to put it out side the public html folder on the server.
please give me any solution or email address of the person who can help me.
Pleaseeeee

Thanks
Chaitenya yadav
Post Reply