Moving images outside of a public document Your host root or restricting access to them using .htaccess, for example
<FilesMatch "\.(gif|png|jpe?g)$">
Order Allow,Deny
Deny from all
</FilesMatch>
And send the images using a PHP script that will check the user's session and send the image only if the user is logged in.
if (!$logged) {
exit();
}
$mimetypes = array(
'.jpg' => 'image/jpeg'
'.jpeg'=> 'image/jpeg'
'.pdf' => 'application/pdf'
);
$file = basename($_GET['file']);
$ext = substr($file, strrpos($file, '.'));
if (file_exists($images_dir . $file) && isset($mimetypes[$ext]) ) {
header('Content-Type: ' . $mimetypes[$ext]);
echo file_get_contents($images_dir . $file);
} else {
}
Slava source
share