• Resolved getsited

    (@getsited)


    Hi, I encountered an error viewing attachments (as a client) due readfile being passed a URL. The following update to the end of the view-attachment function in class-file-uploader.php fixed it:

    //header( "Content-Type: $attachment->post_mime_type" );
    //readfile( $attachment->guid );
    
    /* Fetch local file path for readfile */
    $attachment_meta = wp_get_attachment_metadata($attachment_id);
    
    if(!is_array($attachment_meta)) {
    	wp_die( __( 'The file you requested is not a valid attachment', 'awesome-support' ) );
    } else {
    
    	$upload_dir = wp_upload_dir();
    	$filepath   = trailingslashit( $upload_dir['basedir'] ) . $attachment_meta['file'];
    	$filesize   = file_exists( $filepath ) ? $this->human_filesize( filesize( $filepath ), 0 ) : '';
    
    	if($filesize) {
    		header("Content-Type: $attachment->post_mime_type" );
    		readfile( $filepath );
    	} else {
    		wp_die( __( 'The file you requested cannot be accessed', 'awesome-support' ) );
    	}
    }

    https://wordpress.org/plugins/awesome-support/

Viewing 1 replies (of 1 total)
  • Thread Starter getsited

    (@getsited)

    When debugging this I noticed System Tools wrongly reported the Uploads Folder didn’t exist (wp-content is hardcoded in to the test). Fixed with this update to system-status.php:

    <tr class="alt">
        <td class="row-title">Uploads Folder</td>
        <td>
            <?php
            $upload_dir = wp_upload_dir();
            if ( !is_dir( trailingslashit( $upload_dir['basedir'] ) . 'awesome-support' ) ) {
                if ( !is_writable( $upload_dir['basedir'] ) ) {
                    echo '<span class="wpas-alert-danger">' . __( 'The upload folder doesn\'t exist and can\'t be created', 'awesome-support' ) . '</span>';
                } else {
                    echo '<span class="wpas-alert-success">' . __( 'The upload folder doesn\'t exist but can be created', 'awesome-support' ) . '</span>';
                }
            } else {
                if ( !is_writable( trailingslashit( $upload_dir['basedir'] ) . 'awesome-support' ) ) {
                    echo '<span class="wpas-alert-danger">' . __( 'The upload folder exists but isn\'t writable', 'awesome-support' ) . '</span>';
                } else {
                    echo '<span class="wpas-alert-success">' . __( 'The upload folder exists and is writable', 'awesome-support' ) . '</span>';
                }
            }
            ?>
        </td>
    </tr>
Viewing 1 replies (of 1 total)

The topic ‘Attachments do not display – readfile fix’ is closed to new replies.