0

I've made a file manager application I have an issue when I'm trying to download files The files that are inside the uploads directory and have moved from my php temp directory dont inherit the folder permission so I got this error in php error log

PHP Warning:  readfile(files/xxx.zip): failed to open stream: Permission denied in ...

When I go inside IIS and go into the security tab and apply inherit permissions it works

<?php

    set_time_limit(0);
    ini_set('memory_limit', '2147483648');

    $file = "files/".htmlspecialchars($_GET["file"]);

    $quoted = sprintf('"%s"',addcslashes(basename($file),'"\\"'));
    $size   = filesize($file);
    if (file_exists($file)) {
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");

        header("Content-Type: force-download");

        header("Content-Disposition: attachment; filename=".$quoted);

        header("Content-Transfer-Encoding: binary");
        header('Connection: Keep-Alive');
        header("Content-Length: ".$size);

        ob_clean();
        flush();
        readfile($file);
    } else {
        header("Location: fileNotFound.php?file=$file");
    }
Bill
  • 3
  • 8

1 Answers1

0

Mmm if you can change folder permission, you can solve the problem. Maybe you also need to restart IIS.

Well, you are using ob_clean that works when you discards content of output buffer. Anyway, if you use ob_clean content before call the function you can get that error. So, ... it is possible that you leaved some " " space or other "invisible" character in other php files?

sensorario
  • 20,262
  • 30
  • 97
  • 159