[PHP] Error Downloading files using FOpen

2004-06-04 Thread Gerald Winkler
 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



Re: [PHP] Error Downloading files using FOpen

2004-06-04 Thread Matt Matijevich
[snip]
When you go to download a file off a page it corrupts the download.
[/snip]

not sure what the exact problem is, but have you tried other functions,
like readfile
http://www.php.net/manual/en/function.readfile.php

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



RE: [PHP] Error Downloading files using FOpen

2004-06-04 Thread Winkler, Gerald
That gives me the same junk data problems.

-Original Message-
From: Matt Matijevich [mailto:[EMAIL PROTECTED]
Sent: Friday, June 04, 2004 2:29 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP] Error Downloading files using FOpen


[snip]
When you go to download a file off a page it corrupts the download.
[/snip]

not sure what the exact problem is, but have you tried other functions,
like readfile
http://www.php.net/manual/en/function.readfile.php


**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed.  If you have received this email in error please notify
the sender by email, delete and destroy this message and its 
attachments.

**



Re: [PHP] Error Downloading files using FOpen

2004-06-04 Thread John W. Holmes
Winkler, Gerald wrote:
That gives me the same junk data problems.
Define junk data? How is it corrupting the file? try downloading a 
simple text file with a basic sentence in it. What does it look like 
after it's corrupted?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php