Search code examples
phphtmlformsreadfile

I have troubles with php readfile to insert txt files with varying names into html


I am creating a web page where the user select a number via a form.

HTML:

<form method="POST" style="font-size: 30px">
<input type="number" id="idname" name = "na" value=168 />
<label for="idname" >Number< /label>
<p><input type = "submit" name = "gesendet" value="Submit" />
<input type = "reset" /> </p>
</form>

using php I want to insert a txt file according to the number, such as 12_.txt or 166_.txt

<?php 
$txtfile='"txt/' . $_POST["na"] . '_.txt"';
readfile($txtfile);
?>

The $txtfile string is O.K when "echoing" and the readfile function works with me when I read a file without the $_POST variable, but this simple code is just not working for me !!


Solution

  • Change:

    $txtfile='"txt/' . $_POST["na"] . '_.txt"';
    

    To:

    $txtfile = 'txt/' . $_POST["na"] . '_.txt';
    

    (Notice the extra double quotes)