Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. mod_rewrite image protection
  2. function getImageFromOutside ( $homePath, $file )
  3. {
  4.     if ( file_exists ( $homePath . '/' . $file ) )
  5.     {
  6.         $contents = file_get_contents ( $homePath . '/' . $file );
  7.         return $contents;
  8.     }
  9. }
  10. $homePath = 'some_path/img';
  11.  
  12. if ( isset ( $_GET['uid'] ) )
  13. {
  14.     $img = $_GET['uid'] . '.jpeg';
  15.     header ( 'Content-type: image/jpeg' );
  16.     echo getImageFromOutside( $homePath, $img );
  17. } else {
  18.     print_r ( $_GET );
  19.     echo file_exists ( $homePath . '/' . $file );
  20. }
  21.        
  22. RewriteEngine On
  23. RewriteCond   %{HTTP_REFERER}  !^$
  24. RewriteCond   %{HTTP_REFERER}  !^http://www.yourdomain.com/.*$ [NC]
  25. RewriteCond   %{HTTP_REFERER}  !^http://yourdomain.com/.*$     [NC]
  26. RewriteRule   ^/PublicFiles/*$ /page-about-direct-links.html