Download file from non public html folder with php

后端 未结 2 1023
失恋的感觉
失恋的感觉 2021-01-20 03:24

I have a number of files that are stored on the server, but not in the public_html directory. The idea is that users who are logged in can download the files, using $_SESSIO

2条回答
  •  青春惊慌失措
    2021-01-20 03:54

    If this is outside of the public_html folder then create a php script to file_get_contents from the file .

    here is part of a script I use

    if ($type == "1" && $method == "f"){
        header('Content-type: application/pdf');
    } else {
        header('Content-type: image/jpeg');
    }
    
    $fp = fopen($uploaded_dir . $result['theimage'], "r");
    while ($data = fread($fp, 1024)){
        echo $data;
    }
    fclose($fp);
    

提交回复
热议问题