php - Is there any way to prevent users from seing private pictures using the absolute path? -


imagine situation

  1. user uploads picture see (picture public)
  2. user decides make picture private
  3. picture visible him, since picture set private on db.

there problem this:

the other users can still access picture absolute path. there way prevent this?

store images outside web root, , have php script determines if current user has permission access it, returning image contents if or 403 forbidden error if not.


you can make file look you're serving original image:

http://example.com/images/sunnytrees.jpg

use .htaccess:

rewriteengine on rewriterule images/(.*) image.php?file=$1 [l] 

then image.php can be:

<?php $file = $_get['file']; // use $file file information, eg. in database if( $it_exists && $has_permission_to_view) {     readfile("/root/path/to/real/images/".$file);     exit; } else header("http/1.1 403 forbidden"); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -