savagenoob Posted January 14, 2009 Share Posted January 14, 2009 I wrote this code to write a PDF with the (timestamp).fdf as the name. How do I automatically open this FDF file after it is created? Here is the code I have so far, I left out the database connection and query... while($myrow = mysql_fetch_assoc($result)) { $data['agencyname']=$_SESSION['SESS_AGENCY']; $data['clientname']=$myrow['Last_Name']; $data['date']=date('Y-m-d H:i:s'); require_once 'createFDF.php'; $fdf_file=time().'.fdf'; $fdf_dir=dirname(__FILE__).'/Forms'; $pdf_doc='/BrokerAgreement.pdf'; $fdf_data=createFDF($pdf_doc,$data); if($fp=fopen($fdf_dir.'/'.$fdf_file,'w')){ fwrite($fp,$fdf_data,strlen($fdf_data)); echo $fdf_file,' written successfully.'; } fclose($fp); } ?> Link to comment https://forums.phpfreaks.com/topic/140765-open-pdf/ Share on other sites More sharing options...
savagenoob Posted January 14, 2009 Author Share Posted January 14, 2009 OK, I think I have a start... I am just sending header info and echo'ing the content but it my PDF viewer is saying "file not found or could not be opened." I can see the FDF file in the directory and can open it manually fine so I know its OK. Here is the code I have so far... <?php require_once('auth.php'); $ID = $_GET['ID']; require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $query = "SELECT * FROM clients WHERE ID='$ID'"; $result = mysql_query($query); while($myrow = mysql_fetch_assoc($result)) { $data['agencyname']=$_SESSION['SESS_AGENCY']; $data['clientname']=$myrow['Last_Name']; $data['date']=date('Y-m-d H:i:s'); require_once 'createFDF.php'; $fdf_file=time().'.fdf'; $fdf_dir=dirname(__FILE__).'/Forms'; $pdf_doc='/BrokerAgreement.pdf'; $fdf_data=createFDF($pdf_doc,$data); if($fp=fopen($fdf_dir.'/'.$fdf_file,'w')){ fwrite($fp,$fdf_data,strlen($fdf_data)); echo $fdf_file,' written successfully.'; } fclose($fp); } $size = filesize($fdf_data); $type = filetype($fdf_file); header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$fdf_file"); header("Content-Description: PHP Generated Data"); echo $fdf_data; ?> Link to comment https://forums.phpfreaks.com/topic/140765-open-pdf/#findComment-736835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.