Re: File download problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux