I have a weird problem, maybe one of you can help me figure it out. I have
a server (that is a test box..but that's a different issue) running PHP
4.3.1 RC (I believe. I didn't install it and they laid off the guy who
did..) and it's giving me a weird error.

When you go to download a file off a page it corrupts the download. The code
for the fopen is specifying a binary d/l and not ASCII so it shouldn't be
doing this. However, it is and I can't figure out why.

I've run it through two browsers and even took the php pages off the
production site and literally replaced the files on the test box. Same
errors. When I directly link to the file, it of course works.

I thought I had ruled out the code (and it still seems to be ruled out)
because the exact same procedure works on the production box. One of the
guys who worked here before he quit two weeks ago mentioned something about
having to change the max upload size in the php.ini file becaue of issues
with large .zip files. However this is not an upload issue so I don't think
it's the problem. I changed it anyways (to varying levels) and it still
didn't work.

Oh, the original files are good. I know becase you can go across the network
and open them and they look fine.

Anyone have any ideas? I'm getting nowhere fast.

Oh, it was originally tested using some .xls files, but a few .txt files I
created as a test were altered in the d/l as well...

It's a local file, it has permission to open it, the size is 20,480 bytes
and the size of the dowloaded file comes out at 20,480 bytes, so they match.

The Apache server is 2.0.43.

      Code:

      // Verify current user and their permissions
         //
         $skip = FALSE;

         if( $_SESSION['userid'] == "" ) {
            $errormsg = "You must be logged in to download files.";
            $skip = TRUE;
         }

         if( $_SESSION['providerid'] == "" ) {
            $errormsg = "You must be logged in to download files.";
            $skip = TRUE;
         }

         // Build path
         if ( @$HTTP_GET_VARS['rfile']) {
            $filepath = $_SESSION['Settings']['datapath'] .
$HTTP_GET_VARS['rfile'];
         } else {
            $filepath = $_SESSION['Settings']['datapath'] .
$_SESSION['providerid'] . $HTTP_GET_VARS['file'];
         }

         if(!$skip) {
            if(file_exists($filepath)) {
               // Save an audit log entry of this download

               // Output headers
               header("Cache-Control: private, must-revalidate");
               header("Pragma: private");
               header("Content-type: application/octet-stream\n");
               header("Content-Disposition: attachment;
filename=\"".substr(strrchr($filepath,"/"),1)."\"\n");
               header("Content-length:
".(string)(filesize($filepath))."\n");

               $fd = fopen($filepath,'rb');

               while(!feof($fd)) {
                  print fread($fd, 4096);
                  flush();
               }

               fclose($fd);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to