How to pass varivlle from a PHP file to another PHP file

Asked

Viewed 484 times

0

I have a script that generates a pdf file. The file name is set in Mergepdf.class.php

But I wanted it to be set in the source file (variable $filename), where it calls this php, which is below:

//destination path for the User PDF file:
$nomearquivo = 'teste';
$pdfUserfile = JPATH_SITE.'/pdf/pdf-padrao1.pdf';
copy($pdfUser,$pdfUserfile);
require_once("/home/site/public_html/scripts/pdf/MergePdf.class.php");
MergePdf::merge(
    Array(
        $pdfUserfile,
         $arquivoiptu
    ),
    MergePdf::DESTINATION__DISK_INLINE
);

Then I would need to pass this $filename to Mergepdf.class.php, but I don’t know how to do it.

  • There are many responses on the site that deal with this, including one (that is not yet Inkei above) which is exactly what was covered in your (to use include/require); I suggest a search at the top of the site. As I find other link links in your question as well. It would help if you clicked on [Dit] and explained a little better why you need it, then maybe you can point to the most efficient way for your case.

2 answers

0

uses include in the file you want to use the variable.

for example: arquivoOrigem.php

echo $nominarquivo;

//the result must be 'test' that is set in the file 'Mergepdf.class.php'

0

To use a variable defined in another file in the current file, you must use the declaration include.

Example of use of the statement

php.

<?php 
  $primeiroNumero = 1;
?>

arquivo2.php

<?php 
  include 'arquivo1.php';
  $segundoNumero = 2;

  $soma = $primeiroNumero + $segundoNumero;
  echo $soma; //Mostrará a soma 1+2 = 3
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.