Re: file download through php
- From: csrster@xxxxxxxxx
- Date: 31 Mar 2006 03:25:55 -0800
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
.
- References:
- file download through php
- From: aljosa.mohorovic@xxxxxxxxx
- Re: file download through php
- From: Chung Leong
- file download through php
- Prev by Date: Re: Concatenate, conjoin, meld, extract images
- Next by Date: Re: array problem
- Previous by thread: Re: file download through php
- Next by thread: What is the difference between raw cmd execute on server, and executing by Apache/PHP
- Index(es):
Relevant Pages
|