Closed blenderitalia closed 8 years ago
Hello. What version of BP Docs are you using?
I do have same problem. Files get currupted after download. i am using following versions. Buddypress Docs 1.9.1 buddypress 2.5.3 Wordpress 4.5.3 I also created seperate ticket for this. https://buddypress.trac.wordpress.org/ticket/7152#ticket Can some one please help me?
@blenderitalia Since you got your problem sorted out, can you say what you did to fix the issue/what was causing the problem?
to help some1 in future... I found the solution and it is working fine now. We need to use ob_end_clean(); to clean buffer before giving file path in attachment.php file catch_attachment_request_custom() function.
Here is the code that you can put directly in your function.php
function catch_attachment_request_custom() {
global $bp;
if ( ! empty( $_GET['bp-attachment'] ) ) {
$fn = basename( $_GET['bp-attachment'] );
// Sanity check - don't do anything if this is not a Doc
if ( ! bp_docs_is_existing_doc() ) {
return;
}
if ( ! $bp->bp_docs->attachments->filename_is_safe( $fn ) ) {
wp_die( __( 'File not found.', 'bp-docs' ) );
}
$uploads = wp_upload_dir();
$filepath = $uploads['path'] . DIRECTORY_SEPARATOR . $fn;
if ( ! file_exists( $filepath ) ) {
wp_die( __( 'File not found.', 'bp-docs' ) );
}
$headers = $bp->bp_docs->attachments->generate_headers( $filepath );
// @todo Support xsendfile?
// @todo Better to send header('Location') instead?
// Generate symlinks like Drupal. Needs FollowSymLinks
foreach( $headers as $name => $field_value ) {
@header("{$name}: {$field_value}");
}
ob_end_clean();
readfile( $filepath );
exit();
}
}
global $bp;
remove_action( 'template_redirect', array( $bp->bp_docs->attachments, 'catch_attachment_request' ), 20 );
add_action( 'template_redirect', 'catch_attachment_request_custom' ,20);
Hope it will be helpful.... :)
Thanks for the tip! Pending some testing, we should be able to include this fix in the plugin. (Note to @dcavins - it could be that the file corruption is only showing up when WP_DEBUG errors are being rendered, causing what is often exhibited as a "headers already sent" problem.)
On 07/01/2016 04:36 AM, KaushikGondaliya wrote:
to help some1 in future... I found the solution and it is working fine now. We need to use _ob_endclean(); to clean buffer before giving file path in attachment.php file catch_attachment_request_custom() function.
Here is the code that you can put directly in your function.php
`/**
- Catches bp-attachment requests and serves attachmens if appropriate *
- @since https://github.com/since 1.4 */
|function catch_attachment_request_custom() { global $bp; if ( ! empty( $_GET['bp-attachment'] ) ) { $fn = basename( $_GET['bp-attachment'] ); // Sanity check - don't do anything if this is not a Doc if ( ! bp_docs_is_existing_doc() ) { return; } if ( ! $bp->bp_docs->attachments->filename_is_safe( $fn ) ) { wp_die( __( 'File not found.', 'bp-docs' ) ); } $uploads = wp_upload_dir(); $filepath = $uploads['path'] . DIRECTORY_SEPARATOR . $fn; if ( ! file_exists( $filepath ) ) { wp_die( __( 'File not found.', 'bp-docs' ) ); } $headers = $bp->bp_docs->attachments->generate_headers( $filepath ); // @todo Support xsendfile? // @todo Better to send header('Location') instead? // Generate symlinks like Drupal. Needs FollowSymLinks foreach( $headers as $name => $field_value ) { @header("{$name}: {$field_value}"); } ob_end_clean(); readfile( $filepath ); exit(); } } |
global $bp;
remove_action( 'template_redirect', array( $bp->bp_docs->attachments, 'catch_attachment_request' ), 20 ); add_action( 'template_redirect', 'catch_attachment_request_custom' ,20);`
Hope it will be helpful.... :)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/boonebgorges/buddypress-docs/issues/535#issuecomment-229903297, or mute the thread https://github.com/notifications/unsubscribe/AAPDY1GX1OQCWrdtME5ZMbgHNG_GAboLks5qRN-KgaJpZM4H-gCY.
This'll be part of 1.9.2. Thanks again for the report!
The .zip file downloaded, in frontend are all corrupt and unreadable. exp. http://www.blender.it/docs/