2013-07-19 76 views
0

在我的网站我有一个表与下面的代码:PHP加载文本文件

<table width="100%" id="tabloadwar" cellspacing="1" cellpadding="0" border="0"> 
<?php 

$subdirs = array_map('intval', scandir("/war")); 
$max = max($subdirs); 

for($i=1;$i<=max;$i++){ ?> 
<tr> 
<td width="15%"><?php echo $i; ?></td> 
<td width="85%"> 
<?php $percorso = file("dir1/content.txt"); $line = file($percorso); echo $line?></td></tr> 

<?php } ?> 
</table> 

使用上面的代码,我想创建一个具有尽可能多的行作为目录的计数表在我的服务器。顺便说它不工作,因为我没有看到我的桌子内有任何东西。一排的一个例子是这样的

<tr> 
<td width="15%">1</td> // i value 
<td width="85%">Italy</td> //text on the 1st line of my *.txt file 
</tr> 

而且,而不是name我必须把一个名为dir1/content.txt文件的内容。它不工作,因为我还没有看到任何东西。任何帮助?

+0

'/ war'?也许你的意思是'/ var'?它是否存在? –

+0

不,这个文件夹被称为“战争” –

+1

目前的输出是什么样的?你有任何错误? – DevlshOne

回答

0

您必须缪斯$max代替max这里for($i=1;$i<=max;$i++){

试试这个代码,看看会发生什么..

<?php 
    if (!file_exists("/war")) { 
    echo "'/war' not exists<br />"; 
    } 
    if (!file_exists("dir1/content.txt")) { 
    echo "'content.txt' not exists<br />"; 
    } 
?> 
<table width="100%" id="tabloadwar" cellspacing="1" cellpadding="0" border="0"> 
<?php 
    $subdirs = array_map("intval", scandir("/war")); 
    $max = max($subdirs); 

    for($i = 1; $i <= $max; $i++) { 
?> 
    <tr> 
    <td width="15%"><?php echo $i; ?></td> 
    <td width="85%"> 
    <?php 
     $lines = file("dir1/content.txt"); 
     echo implode("<br />", $lines); 
    ?> 
    </td> 
    </tr> 

<?php 
    } 
?> 
</table> 

你说....rows as the count of directories in my server...
,如果你想在文件夹子文件的数你可以使用globGLOB_ONLYDIR国旗

<?php 
    $dirs = glob("path/to/dir/*", GLOB_ONLYDIR); 
    $total_dirs = count($dirs); 
?>