I can not download files using custom php code
-
Hi everyone,
I use this technique(https://wpmu.org/how-to-build-your-own-wordpress-contact-form-and-why/) to write custom php code without pluggins and until now it works great, but now i get stuck into a problem when trying to download files, seems like wordpress do not like my path or is not recognized, here is a little of my code, i appreciate if you have any idea why is this happening.
I got this from Chrome: Resource interpreted as Document but transferred with MIME type application/octet-stream:
And my file downloads incomplete.
P.D I made a separe example outside wordpress and it works fine.
—————————————————————-A part of my simply code is:
$path = $_SERVER[‘SERVER_NAME’].”:8080/projects/sports/wp-content/whitepapers/logo_america.jpg”;
send_download($path);
function send_download($path)
{
$file = basename($path);
$length = filesize($path);header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename=”‘ . $file . ‘”‘);
header(‘Content-Transfer-Encoding: binary’);
header(‘Expires: 0′);
header(‘Pragma: public’);
header(‘Content-Length: ‘ . $length);
header(‘Accept-Ranges: bytes’);
ob_clean(); //cleans the output buffer
flush();readfile($path);
}
Thank’s in advance guys!!
- The topic ‘I can not download files using custom php code’ is closed to new replies.