【问题标题】:I want to list on HTML table the 2 directories我想在 HTML 表中列出 2 个目录
【发布时间】:2015-04-09 22:10:37
【问题描述】:

我想列出 2 个目录中的文件,但收到以下错误:

参数 #1 不是第 62 行 C:\wamp\www\new.php 中的数组:

$directory = '/openssl/bin/';
$extension = '.pem';
$directory2 = '/openssl/try/bin/';
$extension2 = '*.*';

if ( file_exists($directory) ) {
   foreach(glob($directory.'*'.$extension) as $file){
        foreach(glob($directory2.'*'.$extension2) as $file2){
            $result = array_merge($file, $file2);   // line 76 error 1

?>
    <tr >

我希望输出是 2 个目录中的文件名列表

        <td> <?php echo basename($result); ?></td>  // this should be list all the filename inside the 2 directory in table

file_get_contents(): C:\wamp\www\new.php 中第 76 行的文件名不能为空 第 76 行以下

$data = openssl_x509_parse(file_get_contents($result));

【问题讨论】:

  • 您的预期输出是什么?
  • `
    td> `我想列出两个目录中的文件名
  • 不太确定你想要什么,也许试试这个:pastebin.com/ZZ0ydVQY

标签: php


【解决方案1】:

您好 glob 需要文件的物理路径。所以尝试运行这段代码

$dir = __DIR__;

$directory = $dir.'/openssl/bin/';
$extension = '.pem';
$directory2 = $dir.'/openssl/try/bin/';
$extension2 = '*.*';

if ( file_exists($directory) ) {
    $myArr = array_merge(glob($directory.'*'.$extension), glob($directory2.'*'.$extension2));
    foreach($myArr as $file){
        echo $file;
        echo "<br>";
    }
}

【讨论】:

  • 我删除了我刚刚弄乱了 glob 代码执行的 DIR 非常感谢!
【解决方案2】:
<?php



$directory = '/openssl/bin/';
$extension = '.pem';
$directory2 = '/openssl/try/bin/';
$extension2 = '*.*';

if ( file_exists($directory) ) {
    $myArr = array_merge(glob($directory.'*'.$extension), glob($directory2.'*'.$extension2));
    foreach($myArr as $file){
        echo $file;
        echo "<br>";
    }
}

?>

感谢 volkinc 的帮助和其他人分享他们的 cmets 和建议我在这里得到了答案我只是对 glob 执行代码有点困惑感谢为我安排它 volkinc 干杯!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 2018-10-19
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2012-10-22
    相关资源
    最近更新 更多