Okay, ive sortof got it working but now I have a different error:
Warning: Cannot add header information - headers already sent by (output started at /TNAWeb/kworld/public_html/corporate/file_detail.php:56) in /TNAWeb/kworld/public_html/corporate/file_detail.php on line 60
I can download files and save them locally and I can open and view them BUT when I try to do this in succession I get header errors.
The code I am using is:
$filename=$file;
$file = explode("uploads/",$file);
$file = $file[1];
if(file_exists($filename)){
$FILECMD = '/usr/bin/file';
$contentType = '';
$fp=popen("$FILECMD -bin $filename", 'r');
if (!$fp) $contentType='application/octet-stream';
else {
while($string=fgets($fp, 1024)) $contentType .= $string;
pclose($fp);
}
if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){
// IE cannot download from sessions without a cache
header('Cache-Control: public');
}
header("Content-type: $contentType");
header("Content-Disposition:attachment; filename=\"".$file."\"");
header("Content-length:".(string)(filesize($filename)));
$fd=fopen($filename,'rb');
while(!feof($fd)) {
print fread($fd, 4096);
}
fclose($fd);
header("Connection: close");
}else{
print "File Not Found";
}
To give you more background on my script, I have an include file a the top of the page that handles the style of all my pages. It has already created 'headers' and I am calling the header function again within the same page to handle the popup of the download code (hope that made sense!).
Do I have too many header sessions open? Have I confused the browser (or myself for that matter!).
If I wait a little while before opening or saving the same file again it seems to work. Is there some sort of a built-in timeout?
Any help would be rewarded with a great big hug from me :-)
-vivianp79