Page 1 of 1

Secure folder public_html

Posted: Mon Apr 09, 2007 3:16 am
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

Posted: Mon Apr 09, 2007 3:26 am
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);
 }
}

Posted: Mon Apr 09, 2007 3:42 am
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