Forum Moderators: coopster

Message Too Old, No Replies

Forcing downloads

using PhP to ensure downloads work

         

rocketscience

6:04 pm on Oct 21, 2003 (gmt 0)

10+ Year Member



I need to ensure that a file is treated by all browsers as something to download and not open in a new window. Right now the files are coming out of the data [ie file_view.php?ID=68976 ] and users have to right-click or option-click to download. However, we are finding that lots of users - as many as 50 or 60 in a day - can't figure this out, or lose the file, or somehow interrupt the transfer.

One issue is the headers that we send. A complete list of headers to ensure all browsers download the file would be a good starting point.

I need to develop a rock-solid download application - preferably with completion notification. Has anyone come across anything like this?

rocketscience

7:38 pm on Oct 21, 2003 (gmt 0)

10+ Year Member



For instance, here are the headers we are sending with this file [a jpg].

$fp = fopen($Path,"r");

header( "Cache-control: private" );
header( "Content-type: " . $FileData[mime_fullsize] );
header( "Content-length: " . $Bytes );
header( "Content-Disposition: attachment; filename=" . $FileName );

fpassthru($fp);

DrDoc

8:17 pm on Oct 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

Why doesn't that code work? Or, are you talking about the filename the user is prompted to save the file as?

rocketscience

8:32 pm on Oct 21, 2003 (gmt 0)

10+ Year Member



Thanks. Well, on some browsers, the image is opened in a window, and sometimes it is saved as a PhP file.

Is there a way of tracking download progress?

DrDoc

8:36 pm on Oct 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, make sure the Web server (as well as the PHP engine itself) doesn't output any headers before yours...

sgconard

11:43 pm on Oct 22, 2003 (gmt 0)

10+ Year Member



This worked for me except on IE Mac:

download.php file:
<?php

header("Content-Type: " . filetype($file));
header("Content-Disposition: attachment; filename=$file");
readfile($file);

?>

$file was passed to this page via HTML file with link:

<a href="download.php?file=test.jpg">Download File</a>

Dunno if this helps you at all.

Steve