I am running nginx 1.10.3 and php7.3-fpm. I need to populate a drop-down list on the web page with the filenames of files in a given directory. The problem is that anything in the 'foreach' loop in the php script is NOT being output to the web server. It all works perfectly when using the php-cli.
I suspect that it has something to do with buffers not being flushed and I have tried absolutely everything that I can find on the web to try and solve this problem. Any help getting over this problem will be greatly appreciated!!!
This is my index.php file used for testing:
<!doctype html>
<html lang="en-us">>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>PHP drop-down list population test</h1>
<?php
header('X-Accel-Buffering: no');
header('Cache-Control: no-cache');
header('Content-Encoding: none');
$path = "/root/Music/";
$flist = glob($path . "*.wav");
echo("<form>
");
echo("<select name=\"music\">
");
foreach($flist as $fname) {
$info = pathinfo($fname);
$fn = $info['filename'];
if($idx == 0)
echo("<option value=\"$fname\" selected>$fn</option>
");
else
echo("<option value=\"$fname\">$fn</option>
");
$idx++;
}
ob_end_flush();
flush();
echo("</select>
");
echo("</form>
");
?>
</body>
</html>
Below is the output I get using curl:
<!doctype html>
<html lang="en-us">>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>PHP drop-down list population test</h1>
<form>
<select name="music">
</select>
</form>
</body>
</html>
This is what I expect to get:
<!doctype html>
<html lang="en-us">>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>PHP drop-down list population test</h1>
<form>
<select name="music">
<option value="/root/Music/church-chime.wav" selected>church-chime</option>
<option value="/root/Music/dixie-horn.wav">dixie-horn</option>
<option value="/root/Music/evacuate-alarm.wav">evacuate-alarm</option>
</select>
</form>
</body>
</html>
lbu - Thanks! It is often the simplest things that can bring you undone (Doh!). The problem was indeed a lack of permissions on the directory.
All fixed and working now.
We can consider this question answered!