PHPで小さなファイルマネージャーを作成しました。読み取り、削除、移動、編集、すべてが正常に機能しています。しかし、変更するファイルの内容の表示には問題があります。
前のフォームでは、変更するファイルをユーザーに選択させ、別のページでファイル名を取得し、次のコードでそのコンテンツをテキストエリアに表示します。
<?php
if (isset($_POST['file'])) {
$file = $_POST['file'];
?>
<form action="edit_file_process3.php" method="get">
<p>This is the content of the file <?php echo $file; ?>. Now you can modify it:</p>
<textarea rows="10" cols="70" name="content"><?php readfile($file) ?></textarea>
<p><input type="submit" name="submit" value="edit <?php echo $file; ?>" /> </p>
</form>
<a href="read2.php">Come back to the file manager</a>
初めてファイルを選択すると、適切なコンテンツではなくテキストエリアで、次のように表示されます。
<br />
<font size='1'><table class='xdebug-error xe-warning xe-scream' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> SCREAM: Error suppression ignored for</th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: readfile(prova4.txt): failed to open stream: No such file or directory in C:\wamp\www\LEARNING\Files\edit_file_process3.php on line <i>50</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>144848</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\LEARNING\Files\edit_file_process3.php' bgcolor='#eeeeec'>..\edit_file_process3.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>145248</td><td bgcolor='#eeeeec'><a href='http://www.php.net/readfile' target='_new'>readfile</a>
( )</td><td title='C:\wamp\www\LEARNING\Files\edit_file_process3.php' bgcolor='#eeeeec'>..\edit_file_process3.php<b>:</b>50</td></tr>
</table></font>
このテキストを別のもので上書きすると機能し、次回はテキストエリアにファイルの適切なコンテンツが表示されます。しかし、これを初めて行うのは非常に厄介です。なぜこれが起こるのですか?