Viewing 1 replies (of 1 total)
  • Thread Starter edubz15

    (@edubz15)

    <?php
    $file = $_GET['file'];
    $ext = pathinfo($file, PATHINFO_EXTENSION);
    $match_array =array('pdf','mp3','mpa','ra','wav','wma','mid','m4a','m3u','iff','aif');
    if(in_array($ext,$match_array)){
    header("Content-type: application/".$ext);
    preg_match("/[^\/]+$/", $file, $matches);
    $last_word = $matches[0]; // test
    header("Content-Disposition: attachment; filename=". $last_word);
    readfile($file);
    }
    ?>

    Above is the download.php file that is executed to return a pdf file in my uploads directory to the user.

Viewing 1 replies (of 1 total)
  • The topic ‘PHP get file in uploads directory returns corrupted file’ is closed to new replies.