• Hi,

    I use deployer to deploy my projects. This creates the following directory structure:

    
    /var/www/mywebsite/current -> /var/www/mywebsite/releases/4
    /var/www/mywebsite/releases
    /var/www/mywebsite/shared
    
    where
    /var/www/mywebsite/releases/4/public_html/content/uploads -> /var/www/mywebsite/shared/content/uploads
    

    By default, when I try to set a server-based file attachment (e.g. uploads/file.pdf) this fails with the error “It is not allowed to use files outside the wp-content directory”. This is because wpcf7_is_file_path_in_content_dir returns false. This function includes the following check:

    
    if ( 0 === strpos( realpath( $path ), realpath( WP_CONTENT_DIR ) ) ) {
    return true;
    }
    

    This fails because realpath($path) returns:
    /var/www/mywebsite/shared/content/uploads/file.pdf

    while realpath(WP_CONTENT_DIR) returns:
    /var/www/mywebsite/releases/9/public_html/content

    I have managed to work around this by defining UPLOADS in wp-config, setting this to ‘../content/uploads’ (the ../ is required because my WordPress installation sits one level beneath the site root i.e. public_html/wp). This allows the second function to return true…

    
    if ( defined( 'UPLOADS' )
    	and 0 === strpos( realpath( $path ), realpath( ABSPATH . UPLOADS ) ) ) {
    		return true;
    	}
    

    This still requires me to set the file attachment path to ‘uploads/file.pdf’ because the path is made up using the value of WP_CONTENT_DIR.

    I’m not sure this is a good approach, partly due to the above but mostly because it causes all of the image URLs to include the ../ (which doesn’t seem right!).

    I wonder if it might be possible to filter this function in some way because in reality the file does exist where it is supposed to, it is only the comparison that is failing.

    Hope someone can help.

    Thanks

  • The topic ‘File attachments failing when uploads folder symlinked for deployment purposes’ is closed to new replies.