Jump to content

file access.


forumuser

Recommended Posts

Setup an .htaccess file with a mod_rewrite, redirect all requests for .jpg to a jpegprocess.php file.

 

In this file you check if the user is logged in, if they are you display the image similiar to this code:

 

<?php
if ($isLoggedIn) {
    $image = 'images.jpg'; // somehow get the image out of the url probably using $_SERVER variables
}else {
    $image = 'no-access.jpg';
}


           $file_extension = strtolower(substr(strrchr($image,"."),1));

           switch ($file_extension) {
               case "gif": $ctype="image/gif"; break;
               case "png": $ctype="image/png"; break;
               case "jpe": case "jpeg":
               case "jpg": $ctype="image/jpg"; break;
           }

           if (!file_exists($image)) {
               die("NO FILE HERE");
           }

           header("Content-Type: $ctype");
           header("Content-Length: ".@filesize($filename));
           @readfile("$image") or die("File not found.");
?>

Link to comment
https://forums.phpfreaks.com/topic/43200-file-access/#findComment-209769
Share on other sites

So I never used .htaccess so don't know how to do it. Can you post a link to a good tutorial?

 

From what I could find:

 

Redirect 301 http://me.myhost.com/test/test/*\.jpg http://me.myhost.com/test/login.php

Redirect 301 http://me.myhost.com/test/test/*\.gif http://me.myhost.com/test/login.php

 

doesn't work :(

Link to comment
https://forums.phpfreaks.com/topic/43200-file-access/#findComment-210218
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.