problems with headers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dizeta
Forum Commoner
Posts: 47
Joined: Mon Feb 02, 2004 9:53 am

problems with headers

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not sure here, but try switching "inline" to "attachment".
User avatar
dizeta
Forum Commoner
Posts: 47
Joined: Mon Feb 02, 2004 9:53 am

Post by dizeta »

hi, feyd...

now pdf download works...thanks.

but still have same problems with doc files... :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the doc files may be suffering from bad upload... or bad translation coming out of the database.
User avatar
dizeta
Forum Commoner
Posts: 47
Joined: Mon Feb 02, 2004 9:53 am

Post 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.... :(
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

hmm... maybe is the browser problem...
if u using zip file (zip the pdf and doc)...


i think it can be solve !
User avatar
dizeta
Forum Commoner
Posts: 47
Joined: Mon Feb 02, 2004 9:53 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I noticed that you are passing in a type, and also storing the type.. are these not matching, maybe?
Post Reply