将输入转换为$String问题


Converting Input into a $String Problems

我使用的是一个php表单,用户在输入框中输入文件名,然后表单应该使用$path、$name和$结尾,以创建一个正确的路径来打开文件,并从]no[到]yes[。

但我没有正确的格式,因为它不起作用。如果我在$path中输入所有内容,但它没有正确转换文本框文件名,那么它确实有效。

非常感谢您的帮助!

############### Code Below ###################
<?php
echo "<table border = 0><tr><td align=left valign=center>";

echo "Please paste the file name below:</br>";
echo "<form method='POST' action='3.php'>";
echo "<input type = 'text' name='$name'/>";
echo "<input type='submit' value='Submit'/>";
echo "</form>";
$path="/home/users/web/b1262/moo.mybidszcom/sandbox/";
$ending='.dat';
$file = ("$path$name$ending");
$file_contents = file_get_contents($file);
$fh = fopen($file, "w");
$file_contents = str_replace(']no[',']yes[',$file_contents);
fwrite($fh, $file_contents);
fclose($fh);
echo "</td><td></td></tr></table>";
?>

检查$_POST['theValue']是否已设置,如果未设置,则显示表单,否则执行代码。

if(!isset($_POST['theValue'])){
    echo <<< EOF
    <table border = 0>
        <tr>
            <td align=left valign=center>
                Please paste the file name below:</br>
                <form method='POST' action='3.php'>
                <input type ='text' name='theValue'/>
                <input type='submit' value='Submit'/>
                </form>
            </td>
            <td></td>
        </tr>
    </table>";
EOF;
}else{
    $name = $_POST['theValue'];
    $path="/home/users/web/b1262/moo.mybidszcom/sandbox/";
    $ending='.dat';
    $file = "{$path}{$name}{$ending}";
    $file_contents = file_get_contents($file);
    $file_contents = str_replace(']no[',']yes[',$file_contents);
    file_put_contents($file, $file_contents);
}

您应该像这样修复

############### Code Below ###################
<?php
echo "<table border = 0><tr><td align=left valign=center>";

echo "Please paste the file name below:</br>";
echo "<form method='POST' action='3.php'>";
echo "<input type = 'text' name='name'/>";
echo "<input type='submit' value='Submit'/>";
echo "</form>";
$path="/home/users/web/b1262/moo.mybidszcom/sandbox/";
$ending='.dat';
$name = $_POST['name'];
$file = ("$path$name$ending");
$file_contents = file_get_contents($file);
$fh = fopen($file, "w");
$file_contents = str_replace(']no[',']yes[',$file_contents);
fwrite($fh, $file_contents);
fclose($fh);
echo "</td><td></td></tr></table>";
?>

您的文件名必须是3.php

您的代码不起作用,因为当您将邮件发送到服务器时。您的输入值将存储为$_POST['Your_input_name']$_POST是表单的方法,如果您将表单的方法更改为GET ,它可能为$_GET