Skip to content

Commit 31387fd

Browse files
committed
Enable the APP attachment file download to work correctly rather than just returning a lot of php notices. Fixes WordPress#10372 for trunk props mysz.
git-svn-id: https://develop.svn.wordpress.org/trunk@11810 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 19c135e commit 31387fd

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

wp-app.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ function get_file($postID) {
780780
}
781781

782782
$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
783+
$location = get_option ('upload_path') . '/' . $location;
783784
$filetype = wp_check_filetype($location);
784785

785786
if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
@@ -789,11 +790,19 @@ function get_file($postID) {
789790
header('Content-Type: ' . $entry['post_mime_type']);
790791
header('Connection: close');
791792

792-
$fp = fopen($location, "rb");
793-
while(!feof($fp)) {
794-
echo fread($fp, 4096);
793+
if ($fp = fopen($location, "rb")) {
794+
status_header('200');
795+
header('Content-Type: ' . $entry['post_mime_type']);
796+
header('Connection: close');
797+
798+
while(!feof($fp)) {
799+
echo fread($fp, 4096);
800+
}
801+
802+
fclose($fp);
803+
} else {
804+
status_header ('404');
795805
}
796-
fclose($fp);
797806

798807
log_app('function',"get_file($postID)");
799808
exit;

0 commit comments

Comments
 (0)