저는이 var가 정의되지 않은 이유를 알지 못합니다.PHP, var 정의되지 않았습니다.
if(isset($_POST['test']))
{
$directory = 'C:/Users/Oscar/Documents/test/';
$files = array_diff(scandir($directory), array('..', '.'));
foreach($files as $file):?>
<table border="2px">
<tr>
<td>
<form method="post">
<input type="submit" value="<?php echo $file; ?>" name="file" />
</form>
</td>
</tr>
</table>
<?php endforeach;
}
if(isset($_POST['file']))
{
//print_r($_POST['file']);
echo file_get_contents($directory.$_POST['file']);
}
디렉토리 var가 정의되지 않았습니다. 마지막 "if"에서이를 호출합니다. 이유를 모르겠다
'$ _POST [ 'test']'가 설정되어 있지 않으면,'$ directory'는 절대로 초기화되지 않습니다. –
'$ directory'는 $ _POST [ 'test']가 존재하는 경우에만 초기화됩니다. 그렇지 않으면 해당 코드 분기가 실행되지 않고 var가 결코 –
[PHP, 브라우저에서 파일을 읽는 스크립트]로 복제되지 않습니다 (http://stackoverflow.com/questions/21212769/php-script-for -reading-files-in-browser) –