3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // 使用表格浏览目录的结构 print("<TABLE BORDER=\"1\">\n"); // 创建表格的头 print("<TR><font bgcolor='red'>\n"); print("<TH><font color='red' size=3 >文件名</font></TH>\n"); print("<TH><font color='red' size=3 >文件的大小</font></TH>\n"); print("</font></TR>\n"); $myDirectory = opendir("."); // 建立操作目录的句柄 // 读出目录中的每一个子项 while($entryName = readdir($myDirectory)) { print("<TR>"); print("<TD>$entryName</TD>"); print("<TD ALIGN=\"right\">"); $size=filesize($entryName); if($size <1024) { $FileSize = (string)$size . "字节";} elseif($size <(1024 * 1024)) { $FileSize = number_format((double)($size / 1024), 2) . " KB"; } else { $FileSize = number_format((double)($size/(1024*1024)),2)."MB"; } print($FileSize); print("</TD>"); print("</TR>\n"); } closedir($myDirectory); // 关闭目录 print("</TABLE>\n");
Output for 5.3.0 - 7.1.0
<TABLE BORDER="1"> <TR><font bgcolor='red'> <TH><font color='red' size=3 >文件名</font></TH> <TH><font color='red' size=3 >文件的大小</font></TH> </font></TR> Warning: opendir(.): failed to open dir: Permission denied in /in/rWbEQ on line 9 Warning: readdir() expects parameter 1 to be resource, boolean given in /in/rWbEQ on line 11 Warning: closedir() expects parameter 1 to be resource, boolean given in /in/rWbEQ on line 31 </TABLE>
Output for 4.3.2 - 5.2.17
<TABLE BORDER="1"> <TR><font bgcolor='red'> <TH><font color='red' size=3 >文件名</font></TH> <TH><font color='red' size=3 >文件的大小</font></TH> </font></TR> Warning: opendir(.): failed to open dir: Permission denied in /in/rWbEQ on line 9 Warning: readdir(): supplied argument is not a valid Directory resource in /in/rWbEQ on line 11 Warning: closedir(): supplied argument is not a valid Directory resource in /in/rWbEQ on line 31 </TABLE>
Output for 4.3.0 - 4.3.1
<TABLE BORDER="1"> <TR><font bgcolor='red'> <TH><font color='red' size=3 >文件名</font></TH> <TH><font color='red' size=3 >文件的大小</font></TH> </font></TR> Warning: opendir(.) [http://www.php.net/function.opendir]: failed to open dir: Permission denied in /in/rWbEQ on line 9 Warning: readdir(): supplied argument is not a valid Directory resource in /in/rWbEQ on line 11 Warning: closedir(): supplied argument is not a valid Directory resource in /in/rWbEQ on line 31 </TABLE>