• Resolved fmarzocca

    (@fmarzocca)


    Hi,
    I need to restrict users access to media files (docs, PDF, etc). I have read your page How to Manage Media Access but I don’t want to mess-up with site images. I would like to put all of the files in a subfolder of wp-content/upload so I am guessing that I have to edit the .htaccess file from RewriteCond %{REQUEST_URI} wp-content/uploads/(.*)$ to RewriteCond %{REQUEST_URI} wp-content/uploads/<subfolder>(.*)$
    Am I right?
    In addition, are you aware of any plugin allowing admin to upload files in subfolders of wp-content/uploads?

    Thanks

    Fabio

Viewing 15 replies - 1 through 15 (of 15 total)
  • This is exactly what I did, I modified the .htaccess and it works perfectly. Thus, AAM only handles media files in the subdirectory.
    For your second question, either you use an FTP client software like Filezilla or a form plugin like Caldera Forms (free).

    Thread Starter fmarzocca

    (@fmarzocca)

    I used Filezilla, but then AAM doesn’t show the media file in the Post&Pages->Media list. Neither does WP Media Library, so I can’t set the access rule for it

    • This reply was modified 6 years, 9 months ago by fmarzocca.

    To be able to do this, you must use “WordPress Media Library Folders” plugin (free). From Back-end, you select “Media Library Folders” in the latteral menu, you select the folder in which you want to place your file and drag and drop your file. Your file will appear in the WP media library and in AAM.

    • This reply was modified 6 years, 9 months ago by erisal.
    Thread Starter fmarzocca

    (@fmarzocca)

    Ok. I was hoping not to use another plugin so I was trying to write some code for it.
    I will give it a try!
    Thank you very much.

    Do you want nobody to upload your files from their direct URL?
    Do you want only owners to upload their files from their direct URL?

    Thread Starter fmarzocca

    (@fmarzocca)

    I want nobody “download” the files from direct URL. Uploading them is an admin charge.

    If you want, you can create a .htaccess file which you place in the directory whose content you want to protect. You don’t need a plugin for that.
    Here is the contents of the .htaccess file:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com/.*$ [NC]
    RewriteRule \.*$ – [F]

    Thread Starter fmarzocca

    (@fmarzocca)

    Thank you!

    BtW, I fixed the problem to upload files directly in a subfolder (for a specific Custom Post Type) without using any plugin. If you are interested:

    add_filter( 'wp_handle_upload_prefilter', 'members_pre_upload' );
    function members_pre_upload( $file ) {
        add_filter( 'upload_dir', 'members_custom_upload_dir' );
        return $file;
    }
    
    function members_custom_upload_dir( $param ) {
        $id = $_REQUEST['post_id'];
        $parent = get_post( $id )->post_parent;
        if( "atp_members" == get_post_type( $id ) || "atp_members" == get_post_type( $parent ) ) {
            $mydir         = '/members';
            $param['path'] = $param['basedir'] . $mydir;
            $param['url']  = $param['baseurl'] . $mydir;
        }
        return $param;

    This means that you have created a CPT from which you download your files?
    What did you choose as a solution to protect your files?

    Thread Starter fmarzocca

    (@fmarzocca)

    Only registered users can download the pdf files in the members area.

    Well, and for this you don’t need AAM, just .htaccess file.
    And when you want upload a file, you don’t use Filezilla but you do it from the Media area of the WordPress back-end ?

    Thread Starter fmarzocca

    (@fmarzocca)

    Yes. When I am in the CPT form (I have a button to “upload” a file), my hook intercepts it, verify that it is a request from CPT and save the file in the uploads/members folder. The file then is also listed normally in MEdia Library with his own correct url.

    Thread Starter fmarzocca

    (@fmarzocca)

    This is the htaccess snippet I am using:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_URI} (\.pdf|\.doc|\.docx)$
    RewriteCond %{REQUEST_URI} wp-content/uploads/members/(.*)$
    RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
    RewriteRule .*\.(pdf|doc|docx)$ https://<my domain name> [NC]

    Thank you for this exchange.

    how to restrict tags & media files to users of roles editor reporter also accessing other users images can edit delete features is appearing how to restrict media pictures only can edit hist pictures only not to other ones

    please help me

    waiting your reply

    thanking you,

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Media Access?’ is closed to new replies.