开发者

Edit text from php document

开发者 https://www.devze.com 2023-02-06 19:59 出处:网络
I have this php document called: pdf5.php In that document I have these lines : $pdf->setSourceFile(\'h.pdf\');

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..


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!


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!";
//...
0

精彩评论

暂无评论...
验证码 换一张
取 消