Attachments do not display – readfile fix
-
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' ) ); } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Attachments do not display – readfile fix’ is closed to new replies.