Thanks for the reply.
I think I found the problem here: The php file was saved with UTF-8
encoding, and for some unknown reason it was adding the UTF-8 BOM to the
output as well. I just saved the PHP file as ANSI, and it worked like a
charm.
Thank you for all your help :)
Stefano
Ashley Sheridan wrote:
I had a similar problem with a script I was using to stream video clips
to a user from a directory that was not accessible through the web.
Turned out I had already sent some HTML content down to the browser
without realising it. I'll go out on a limb here and guess that those
three bytes you're seeing are always the same three? If so, it's highly
likely you are sending some content to the browser ahead of the file,
which gets added to the beginning of the file.
Ash
www.ashleysheridan.co.uk
------------------------------------------------------------------------
Subject:
Re: File download problem
From:
Stefano Noffke <stefano.noffke@xxxxxxxxxxxxxxxxxxxx>
Date:
Tue, 19 Aug 2008 15:17:25 +0200
To:
php-general@xxxxxxxxxxxxx
To:
php-general@xxxxxxxxxxxxx
I checked the files with an HEX editor, and I found that each downloaded
file starts with "EFBBBF", and after those three bytes follows the
regular file.
If I delete those three bytes, I can open the files just fine.
Now the question is: Why do I get those three extra bytes at the
beginning of each file I download with my script?
Thanks
Stefano
Stefano Noffke wrote:
Hi,
Thank you for your reply. I tried your code, but the problem remains.
I still can download PDF, TXT, and MP3 fine, but the ODT, DOC, and JPG
are still corrupted.
I wonder why it works with some files and not with others...
Stefano
Ashley Sheridan ha scritto:
Hi Stefano,
You can use this code instead to read in the file and output it to the
browser, as it is binary safe. I've used it for the same reason you
require, and it works fine with video clips.
$fp = fopen($path, "rb"); while(!feof($fp)) { print(fread($fp,
1024)); flush($fp); } fclose($fp); exit();
The "rb" in the fopen function instructs PHP to open the file for
reading in a binary safe manner.
Hope this helps.
Ash
www.ashleysheridan.co.uk
------------------------------------------------------------------------
Oggetto:
File download problem
Da:
Stefano Noffke <stefano.noffke@xxxxxxxxxxxxxxxxxxxx>
Data:
Mon, 18 Aug 2008 16:01:22 +0200
A:
php-general@xxxxxxxxxxxxx
A:
php-general@xxxxxxxxxxxxx
Greetings,
I need to create a script to let registered users to download files
from a non-public folder.
The files name, type, and size are stored in a MySQL Database. The
user need to click on a link, and a PHP script should handle the
download of the file.
Here is how I organized it:
The script gets the ID from the $_GET array, retrieve the name, type,
and size from the database, and then it sends the following:
[CODE]
header("Content-Type: $type");
header("Content-Length: " . filesize($fileNameWithAbsolutePath));
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: private");
header("Content-Disposition: attachment; filename=\"$fileName\"");
readfile($fileNameWithAbsolutePath) or die("File not found.");
[/CODE]
This script needs to work with any file type. I checked it and it
works fine with PDF, TXT, and MP3 for example, but not with ODT, DOC,
or JPG which are corrupted and won't even open. Those are the only
files I tried so far.
I should add that the connection to the web page is encrypted through
SSL. The server (Fedora 9) runs Apache 2.2.9, PHP Version 5.2.6, and
MySQL version 5.0.51a.
I cannot find any solution to this problem, and I hope that anyone
here can help me.
Thank you.
Stefano
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php