tags:

views:

47

answers:

2

hi I coded the code bellow my self, and I get a f*ing internal server error every time, I'm getting sick and tired of this, please help:

<?
    function doer($str)
    {
      $d = base64_decode($str);
      $a = explode('<||>',$d);
        $v =array(
          'path' => $a[0],
          'size' => $a[1],
          'type' =>$a[2]
        );
        return $v;
    }
  ?>
  <?
                  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
                  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                  $a= doer($_GET['d']);
                  $type = $a['type'];
                  header("Content-type: application/".$type.";\n"); //or yours?
                  header("Content-Transfer-Encoding: binary");
                  $filename = $a['path'];
                  $len = $a['size'];
                  header("Content-Length: $len;\n");
                  $outname="downfile.".$type;
                  header("Content-Disposition: attachment; filename=\"$outname\";\n\n");
                  $filename = 'http://example.com/tst/'.$a['path'];
                  readfile($filename);
  ?>

more info: this script should be putted on (http://example.com/tst/) and all of files are stored in (http://example.com/tst/downloads). also there's no .htaccess file

+2  A: 

There are one blank space...

?>
<?

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. 1

Felipe Cardoso Martins
kaveh taher, pay attention in answer of Marc B! this is a fail of security... the user can get information of your server or application
Felipe Cardoso Martins
+1  A: 

Is there any reason you're using file_get_contents() with a url, pointing at the same server the script itself is running from? This causes a second HTTP request to be fired off, and if the URL points at a password protected resource (or one requiring a valid session), the file_get_contents() call will not able to handle that.

Is there anything in the server's error log as to what the bad/invalid header is? Have you tried saving the generated header strings to a file to make sure they're being generated correctly?

Marc B