• 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!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter chr1smtz

    (@chr1smtz)

    A friend of mine (Alexis Mejia “the master”) helped me to find the solution, before you have to include this

    require_once(‘/../../../wp-load.php’);

    $file = “img.jpg”

    $path = TEMPLATEPATH.”/../admin/images/”.$file;

    obviously everything depends on your project structure!

    SOLVED!

    Thread Starter chr1smtz

    (@chr1smtz)

    And change this function: ob_end_clean();

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I can not download files using custom php code’ is closed to new replies.