Jump to content

[SOLVED] Downloading pdf's from server


graham23s

Recommended Posts

Hi Guys,

 

i have a button on a form that when clicked should download the users .pdf document that they have uploaded but, when i click it, all i get is .txt file with a warning in it

 

button:

 

<form action=\"downloadcv.php?id=$recipientsid\" method=\"post\"><input type=\"hidden\" name=\"hiddenusersid\" value=\"$recipientsid\"><input type=\"submit\" class=\"btn\" value=\"Download My CV\"></form>

 

code:

 

<?php
     ## the includes
     include("includes/sessions.php");
     include("includes/db_connection.php");
     include("includes/constants.php");
?>
<?php
#################################################
# downloadcv.php
#################################################
  $usersid = mysql_real_escape_string($_POST['hiddenusersid']);

  ## query the cv db
  $qcv = "SELECT * FROM `userscvs` WHERE `userid`='$usersid' LIMIT 1";
  $rcv = mysql_query($qvc);
  $row = mysql_fetch_array($rcv);
  
  ## vars
  $cvid = $row['id'];
  $cvuserid = $row['userid'];
  $cvname = $row['cvname'];
  
  ## headers
  header("Pragma: public"); 
  header("Expires: 0"); 
  header("Content-Type: application/force-download");
  header("Content-Type: application/pdf"); 
  header("Content-Disposition: attachment; filename=\"$cvname\"");
  @readfile("cvs/$cvname"); 
?>

 

i pass the users id through, check it against the "userscv" table then grab the variables and then it should download, is there anything i have missed here?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/80872-solved-downloading-pdfs-from-server/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.