Re: file download through php




Chung Leong wrote:
aljosa.mohorovic@xxxxxxxxx wrote:
I have a problem when doing indirect download of file through php, when
I click on download link Firefox and Internet Explorer give me same
options: Open and Save. Firefox opens file directly from Internet and
downloads without problem.

Internet Explorer saves file on local disk and I can open it from disk
correctly but when I try to open it directly from Internet it responds
with "There was an error opening this document. This file cannot be
found.", concrete situation in my usage is Pdf document. Below is my
concrete code, any suggestions are appreciated.


<?php
ob_start();
include_once("config.php");
ini_set('display_errors', 'Off');
error_reporting(0);

$args = trim($_SERVER["PATH_INFO"]);
$args = preg_replace("/^\//i", '', $args);
$argv = explode('/', $args);
$id = (int)$argv[0];

import('dao.fm.file');
$f = fm_file::instance($id);

if($f->get('id') < 1) {
die('No file.');
}
header('Content-Disposition: attachment');
header('Accept-Charset: UTF-8');
header('Content-Type: '.$f->get('type').'; charset="UTF-8";');
readfile(get('FILES').'/'.$f->get('id'));
ob_end_flush();
?>

The problem you encountered has to do with the dumb way IE's caching
mechanism works. If it receives a no-cache directive from the server,
IE would immediately remove the file after it's downloaded. The
external program doesn't get a chance to open it.

Add this and see if that fixes the problem:

header('Cache-Control: ');

I am wrestling with a very similar problem. Here is some of my php
script (after taking the
above suggestion on board):

Header("Content-Type: application/octet-stream ");
Header("Content-Disposition: attachment; filename=\"$filename\"");
Header("Content-Length: $length");
Header("Cache-Control: ");

clip_tv();
while (@ob_end_flush());
exit();

function clip_tv() {
global $startTime, $duration, $fileLocation, $bitrate;
$startBytes=$startTime*$bitrate;
$cutterCommand = "/home/fedora/bin/mencoder 3>&1 1>&2 -quiet -sb
$startBytes -endpos $duration -oac copy -ovc copy -of mpeg
$fileLocation -o /proc/self/fd/3 2>/dev/null";
passthru($cutterCommand);
}

I (left-) click on a link which calls this script with some request
parameters. IE pops up
a box asking me to open or save. I select "save" and browse to a file.
IE downloads until
it reaches, supposedly, 99% of the total stream length and then "Cannot
copy file. Source
file or disk is unreadable" (my translation).

Firefox is no problem. Incidentally, IE also ignores the suggested
filename in the Content-disposition header.

--
Colin Rosenthal

.



Relevant Pages

  • Re: Firefox stole IEs associations!
    ... Links in e-mails still automatically open firefox. ... Where is the setting to make IE the default,not just ask it to check if it is: and to take back all the extensions - visible or otherwise - that mozilla has changed:? ... Check the box "Internet Explorer should check to see whether it is the ... Doing so should generate a prompt to make ie the default next time it opens: ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Thank You
    ... Are you suggesting that Firefox disable downloads entirely? ... I don't *believe* that Internet Explorer has the ability to stop ... 50 or so individual FF windows open and yes it is FF windows, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Changing browser
    ... Control Panel | Add/Remove Programs | Set Program Access and Defaults and make FireFox the default browser. ... When I press E-mail, it opens Outlook Express and when I press Internet, it opens Internet Explorer and takes me right to my Comcast homepage. ... I just downloaded Mozilla Firefox and wondered if you can tell me how to change it so that when I press Internet it would open Firefox instead and still take me to the comcast homepage. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Thank You
    ... And FF can not stop this unless they do not allow downloads, which last I checked they don't. ... The latest version of Firefox will run on *any* version of Windows since Win9x in addition to Linux, FreeBSD, etc. ... Furthermore, on the topic of security, there have been serious holes in Internet Explorer that were announced *years* ago that have still not been corrected. ... Firefox *is* more secure. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Internet Explorer address bar URLS still open in firefox
    ... >> bar it opens in Firefox. ... to go into Internet Explorer> Programs and check the "Internet Explorer ... open links in email via Internet Explorer again. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)