从一个PHP文件到另一个PHP文件的PHP变量

时间:2014-12-14 20:00:54

标签: php global-variables session-variables

我有一个基于用户交互生成图像的php文件。然后我想将$ image变量发送到我的pdf.php,其中fpdf可以将其放在pdf中。

我有两个脚本独立工作但是当我尝试使用

发送变量时
_SESSION['image1'] or global $image1 

第二个php文件没有收到信息。

我做错了什么?

<?php
session_start();
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$_SESSION['graphPath'] = "./temp/graph1".uniqid().".png";
$_SESSION['graphs'] = array();
array_push($_SESSION['graphs'], $_SESSION['graphPath']);
imagepng($img, $_SESSION['graphPath']);
$graphAns1 = $img;
$_SESSION['image1'] = $_SESSION['graphs'][0];

$runThis = shell_exec('php send.php');

require('PHPMailer/class.phpmailer.php');
define('UPLOAD_DIR','./');


/* ***********  Start mail   ************* */

//$_SESSION[attachment]


$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->CharSet="UTF-8";
$body = "this is the body;
$mail->IsHTML();

$mail->AddReplyTo("aaa@aaa.com","aaa"); // address to send from + name
$mail->SetFrom("aaa@aaa.com","aaa"); // address to send from + name

// both are required and must be the same.

//$mail->AddReplyTo();

$mail->Timeout = 120;

$address = "aaa@gmail.com"; // address to send to 

$mail->AddAddress($address,"sender");

$mail->Subject = "pdf email test";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);


$mail->AddStringAttachment($_SESSION['attach'] , "NEWattachment.pdf");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";



 //$file1 = glob('./temp/'.$image);
//unlink($file1);

// deleting files after -- not sure sometimes buggy.

  exit;
}
?>

*********** PHP文件2 *************

<?php
session_start();

require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
//************

define('UPLOAD_DIR','./');

$_SESSION['pdfT'] = 'the pdf script is loading';
echo($_SESSION['image1'].'image1');

//define('FPDF_FONTPATH', './font');

/* ***********  Start pdf   ************* */

$pdf =& new FPDI();
$pdf->AddPage();

//Set the source PDF file
$pdf->setSourceFile("4.pdf");


$tplidx1 = $pdf->importPage(1);    
$pdf->useTemplate($tplidx1, null, null, 215.9, 279.4, TRUE);
// Generate some content for page 2  


//Import the first page of the file
$tppl = $pdf->importPage(2);
$pdf->addPage(); 
//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tppl, null, null, 215.9, 279.4, TRUE);



//Select Arial italic 8
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(0,0,0);


chown($_SESSION['image1'], username);
chmod($_SESSION['image1'],777);
//$pdf->Image('2.jpg',,120,150,100);// x y h w
$pdf->Image($_SESSION['image1'],45,70,130,72, 'PNG');// x y w h 'png'






$tplidx3 = $pdf->importPage(3);  
$pdf->addPage();  
$pdf->useTemplate($tplidx3, null, null, 215.9, 279.4, TRUE);
// Generate some content for page 3  

$tplidx4 = $pdf->importPage(4);  
$pdf->addPage();  
$pdf->useTemplate($tplidx4, null, null, 215.9, 279.4, TRUE);
// Generate some content for page 3  

$tplidx5 = $pdf->importPage(5);  
$pdf->addPage();  
$pdf->useTemplate($tplidx5, null, null, 215.9, 279.4, TRUE);
// Generate some content for page 3  

$tplidx6 = $pdf->importPage(6);  
$pdf->addPage();  
$pdf->useTemplate($tplidx6, null, null, 215.9, 279.4, TRUE);
// Generate some content for page 3  


//$pdf->Write(0, “testing testing testing testing ”);

$attachment = "./temp/attachment".uniqid().".pdf";
$_SESSION[$attachment] = $pdf->Output("Practice.pdf", "S"); // d send to browser, F send to local
//$pdf->Output($_SESSION[$attachment], "F");
// I auto open in browser window.

0 个答案:

没有答案