我很感激大家给我的帮助。现在,我的下拉框似乎在变化,但是它是空白的。我正在使用的当前代码编辑如下:
<input type="hidden" name="Action" value="EDIT" /><input type="hidden" name="Selection" id="Selection" value="-1"><div>Below is the list of your saved codes. To edit your codes, select it from the list.</div>
<select>
<?php
$directory = realpath(dirname(FILE)) . '/../users/' . $_SESSION['username'];
$files = scandir( $directory ) ;
foreach( $files as $file )
{
if ( ! is_dir( $file ) )
{
echo "<option>" . $file . "</option>";
}
}
?>
</select>当我检查页面上的空下拉元素时,我得到以下内容:
警告: scandir(/home/revo/public_html/evo/../users/Addiction) function.scandir:未能打开dir:在第117行/home/revo/public_html/evo/codesaveindex.php中没有这样的文件或目录
警告: function.scandir:(errno 2):第117行/home/revo/public_html/evo/codesaveindex.php中没有这样的文件或目录
警告:为第119行中的/home/revo/public_html/evo/codesaveindex.php中的foreach()提供的参数无效
发布于 2015-03-09 00:47:16
我认为这应该可以将DIR替换为您想要的路径。
<select>
<?php
$directory = __DIR__;
$files = scandir( $directory ) ;
foreach( $files as $file )
{
if ( ! is_dir( $file ) )
{
echo "<option>" . $file . "</option>";
}
}
?>
</select>发布于 2015-03-09 00:46:44
您的问题是输出一个<select>标记,然后开始构建一个带有级联的php变量$Selection (这是错误的,因为您从未在连接之前初始化该变量)。
看看这是否有效:
<input type="hidden" name="Action" value="EDIT" /><input type="hidden" name="Selection" id="Selection" value="-1"><div>Below is the list of your saved codes. To edit your codes, select it from the list.</div>
<?php
// match all files that have .txt extension
$file_matcher = realpath(dirname(__FILE__)) . '/../users/' . $_SESSION['username'] . '/*.{txt}';
//Initialize variable $Selection
$Selection = '<select size="1" name="CodeList" id="CodeList" onchange="CodeChange();"><option value="0">(Add New Code)</option>';
foreach( glob($file_matcher, GLOB_BRACE) as $file ) {
$file_name = basename($file);
//Concatenate variable $Selection
$Selection .= "<option value='$file'>$file_name</option>\n";
}
//Finish HTML source concatenation on $Selection
$Selection .= '</select>';
//Output the HTML
echo $Selection;
?>发布于 2015-03-09 02:00:04
您有一个有点复杂的目录路径。
$file_matcher = realpath(dirname(__FILE__)) . '/../users/' . $_SESSION['username'] . '/*.{txt}';如果目录无效,您将找不到任何文件,也不会有填充的选择。
只是为了测试,尝试一个简单的目录-没有任何vars看看它是否工作。我敢打赌,在尼罗克特的帮助下,一定会的。+1至尼罗克特。
https://stackoverflow.com/questions/28933561
复制相似问题