Page 1 of 1

problems with headers

Posted: Thu May 27, 2004 2:51 am
by dizeta
hi there,

i've a news system script, and i give to users the possibility to download pdf and doc files.
the first problem is, when i click on pdf files, browser open its. i need to download pdf not open.

second problem is, when i download doc files and open into msword, the file results unreadable.

this is the script:

Code: Select all

<?php

include("dbconnect.php");

switch($_GET['type']) {
   case 'pdf':
           $query = "SELECT DatiBinari, Nome, Type FROM pdf WHERE id_sharepdf = '{$_GET['Id']}'";
    break;
   case 'doc':
         $query = "SELECT DatiBinari, Nome, Type FROM doc WHERE id_sharedoc = '{$_GET['Id']}'";
  break;
  default:
    echo "Dati non corretti";
    exit;
    break;

}

$result = mysql_query($query) or die(mysql_error());
if($result) {
   $ris = mysql_fetch_assoc($result);
  
 
 // INTERNET EXPLORER
if(ereg("MSIE ([0-9].[0-9]{1,2})", $_SERVER["HTTP_USER_AGENT"])) {

header("Content-Type: {$ris['Type']}");
header("Content-Disposition: inline; filename={$ris['Nome']}");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");

} else {

header("Content-Type: {$ris['Type']}");
header("Content-Disposition: attachment; filename={$ris['Nome']}");
header("Expires: 0");
header("Pragma: no-cache");
  
  }  
 }  
 echo $ris['DatiBinari'];
 exit;

?>
solutions?

thanks

Posted: Thu May 27, 2004 3:01 am
by feyd
not sure here, but try switching "inline" to "attachment".

Posted: Thu May 27, 2004 3:07 am
by dizeta
hi, feyd...

now pdf download works...thanks.

but still have same problems with doc files... :(

Posted: Thu May 27, 2004 3:16 am
by feyd
the doc files may be suffering from bad upload... or bad translation coming out of the database.

Posted: Thu May 27, 2004 9:40 am
by dizeta
i've tried with different files doc, and i'm using the same upload script, in others scripts... :?:

i don't understand where can be the problem.... :(

Posted: Thu May 27, 2004 9:52 am
by kevin7
hmm... maybe is the browser problem...
if u using zip file (zip the pdf and doc)...


i think it can be solve !

Posted: Thu May 27, 2004 11:15 am
by dizeta
kevin7 wrote:hmm... maybe is the browser problem...
if u using zip file (zip the pdf and doc)...


i think it can be solve !
ok, but

1) why pdf files download, works?
2)i've tried with a different type of browser ( IE, Mozilla, Opera) and i've the same problem...

when i try to open a downloaded file doc, msword shows me:
it seems that keep into memory pdf format or something... :?
http://www.studiosdz.com/prove/Snap1.jpg

Posted: Thu May 27, 2004 1:11 pm
by feyd
I noticed that you are passing in a type, and also storing the type.. are these not matching, maybe?