Re: file download through php
- From: "Chung Leong" <chernyshevsky@xxxxxxxxxxx>
- Date: 17 Mar 2006 13:47:24 -0800
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: ');
.
- Follow-Ups:
- Re: file download through php
- From: csrster
- Re: file download through php
- References:
- file download through php
- From: aljosa.mohorovic@xxxxxxxxx
- file download through php
- Prev by Date: Re: What is the difference between raw cmd execute on server, and executing by Apache/PHP
- Next by Date: Re: Retrieve fields with similar values from 2 tables?
- Previous by thread: Re: file download through php
- Next by thread: Re: file download through php
- Index(es):
Relevant Pages
|