Rendering files efficiently with php / apache -


i developing website users can upload images.

the users should allowed see images when logged in.

i can see facebook doing rendering private photos through photo.php this:

<img src="https://www.facebook.com/photo.php?fbid=10231522709593244&set=a.10150407561663244.3514699.73368243&type=1"> 

i can same thing this:

photo.php:

if ($user_logged_in) {     $filename='/home/protectedfolder/'.$_get['fbid'].'.jpg';   // got idea...     header("content-type: image/jpg");      header('expires: 0');                         readfile($filename);         } 

...and works, slow, though server powerful.

how can in more efficient way? have tried file_get_contents , curl, did not help. have tried enabled cashing seems ignored.

do need change apache configuration or need apache modules?

you should consider using php add css values (fig. 1) head if user or is-not logged in, add script (fig. 2) .htaccess prevent other sites showing images.

this should me faster trying have php read file.

fig 1:

<head> ... <?php if(!$is_logged_in) { echo '<style>.private_image { display:none; }</style>'; } </head> 

fig 2:

rewriteengine on rewritecond %{http_referer} !^$ rewritecond %{http_referer} !^http(s)?://(www\.)?yourdomain.com [nc] rewriterule \.(jpg|jpeg|png|gif)$ - [nc,f,l] 

 


also:

it may idea remove or replace image tags on page rather css value.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -