php - .htaccess restrict media folder in wordpress -


i trying figure out how use in wordpress environment:

from: block direct url access allow download

1st: .htaccess(in uploads folder)

order deny,allow deny 

2nd: (in wp-content folder "thephpfile.php")

if( !empty( $_get['name'] ) ) {   //if( is_user_logged_in() )   //{     $file_name = preg_replace( '#[^-\w]#', '', $_get['name'] );     $the_file = "{$_server['document_root']}/wp-content/uploads/2013/05/oprotunity.jpg";     //$the_file = "{$_server['document_root']}/wp-content/uploads/2013/05/{$file_name}.jpg";     if( file_exists( $the_file ) )     {       header( 'cache-control: public' );       header( 'content-description: file transfer' );       header( "content-disposition: attachment; filename={$the_file}" );       header( 'content-type: image/jpeg' );       header( 'content-transfer-encoding: binary' );       readfile( $the_file );        exit;     }   //} } 

if comment out is_user_logged_in statement works charm. add conditional statements can serve file role or specific users id or name. can leg work not sure how needed functions wordpress.

in src area put (wp-content directory)/thephpfile.php?name=my-image-name

how use wordpress functions in file?

in order call wordpress functions arbitrary script you'll need include wordpress "start". not index.php. file need include wp-blog-header.php wordpress root directory. once loaded, give access wordpress functions.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -