0

I have this php document called: pdf5.php

In that document I have these lines :

$pdf->setSourceFile('h.pdf'); 

I want to be able to edit these lines 'h.pdf' with a code or script.


The problem is that I would like to do it this way:

I have another php document called editpdf.php

with these inputs

<input type="text" value="h.pdf" /> <br>
<input type="text" value="" /> - Lets say the user puts: **f.pdf**
<input type="submit" name="submit" value="Modify" />

and when the user clicks Modify, the -h.pdf- from -pdf5.php- changes to -f.pdf-

like this: $pdf->setSourceFile('f.pdf');


I think I found something similar but it only edits the same page and it doesnt let a user modify it.

JavaScript replace()

  <script type="text/javascript">
  var str="Visit Microsoft!";
  document.write(str.replace("Microsoft", "hello"));

so any ideas??? I dont know if I am making myself clear enough... ?? thnx in advanced..

Norman
  • 79
  • 1
  • 1
  • 7

2 Answers2

0

You'll have to send your form (preferably using POST) and use that POSTed variable as a parameter to $pdf->setSourceFile, like:

<form method="POST" action="…">
   <input type="text" name="old" value="h.pdf" /> <br>
   <input type="text" name="new" value="" />
   <input type="submit" name="submit" value="Modify" />
</form>

and PHP:

$newvalue = $_POST['new']; // but: always do some sanity checks!!!
$pdf->setSourceFile($newvalue);

As already said: always check the values you receive as input from the user (e.g., using a hash table) before feeding them to functions!

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
  • thnx! finally! at least you helped... other people just commented .. :D – Norman Jan 23 '11 at 18:36
  • is there a way to make set source file blank with no error? - example $pdf->setSourceFile(N/A); ... because if there is no input it gives this error: FPDF error: Cannot open ! - i dont know if you are familiar with fpdf or fpdi in this case – Norman Jan 23 '11 at 18:59
  • @Norman – Then you should omit reading the source file; according to [FPDI::setSourceFile()](http://www.setasign.de/support/manuals/fpdi/fpdi/fpdi-setsourcefile/) a file name is mandatory. – Marcel Korpel Jan 23 '11 at 19:14
0

If I get your question properly, you need to modify a PHP variable. To do that, you can GET/POST to that page through a form, or through AJAX

In HTML

<form method="GET" action="">
    <input type="text" name="old" value="h.pdf" /> <br>
    <input type="text" name="new" value="" /> <br/>
    <input type="submit" name="submit" value="Modify" />
</form>

In PHP:


//...Use the foll. way
if (file_exists($_GET['new']))
    $pdf->setSourceFile($_GET['new']);
else
    echo "ERROR! No file found!";
//...
UltraInstinct
  • 43,308
  • 12
  • 81
  • 104