Download files from server php

前端 未结 4 1179
余生分开走
余生分开走 2020-11-28 09:07

I have a URL where I save some projects from my work, they are mostly MDB files, but some JPG and PDF are there too.

What I need to do is to list every file from tha

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 09:25

    Here is the code that will not download courpt files

    $filename = "myfile.jpg";
    $file = "/uploads/images/".$filename;
    
    header('Content-type: application/octet-stream');
    header("Content-Type: ".mime_content_type($file));
    header("Content-Disposition: attachment; filename=".$filename);
    while (ob_get_level()) {
        ob_end_clean();
    }
    readfile($file);
    

    I have included mime_content_type which will return content type of file .

    To prevent from corrupt file download i have added ob_get_level() and ob_end_clean();

提交回复
热议问题