filesize():特定路径的统计信息失败-PHP [英] filesize(): stat failed for specific path - php

查看:83
本文介绍了filesize():特定路径的统计信息失败-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的文档管理脚本,需要获取表中的文件大小和文件类型/file或folder/.不知何故,它无法进入提及目录.请尽可能提供帮助:

i am coding a simple doc managing script and need to get the file size and file type /file or folder/ in a table. somehow it doesn't work into the mention directory. please help if possible:

    <?php
$path = "./documents";
$dh = dir($path);
while( ($file=$dh->read()) ) 
{
    if( $file=="." || $file=="..")continue;
    echo "<tr><td><a href='download.php?f=$file' title='Click to Open/Download'>$file</a></td>";
    echo "<td>";
    echo (is_file($file))? "<img src='file.jpg'/> FILE" : "<img src='folder.jpg'/> FOLDER ";
    echo "</td><td>" .filesize($file)."</td>";
    echo "<td><input type='checkbox' name='delete[]'/></td></tr>";
}
?>

它实际上确实有2个错误-一个错误的文件大小不适用于该位置,如果我将其更改为."的路径.-一切正常,但是如果我尝试更改到我需要的文件夹/documents ...一切都变糟了,其次-它也没有正确的图标文件,同样的问题.谢谢

it does actually has 2 errors - one the file size doesn't work for the location, if i change it to path to "." - everything is ok, but if i try to change to the folder where i need it /documents ...all goes bad, and secondly - it doesn't take the right icon file as well, same type of problem. thank you

推荐答案

问题是, $ file 只是没有目录前缀的文件名,因此对其进行检查将不起作用.一种方法是使用绝对文件名的变量(例如 $ realfile ).然后,您必须更改代码并将此变量用于文件检查:

Problem is, $file is only the filename without the directory prefix, so checking on it won't work. One way would be to have a variable with the absolute filename (say $realfile). You'd then have to alter your code and use this variable for the file checks:

<?php
$path = "./documents";
$dh = dir($path);
while(($file=$dh->read()) !== false) {
    if( $file=="." || $file=="..") continue;
    // have a new variable for the real filepath
    $realfile = $path . "/" . $file;
    echo "<tr><td><a href='download.php?f=$file' title='Click to Open/Download'>$file</a></td>";
    echo "<td>";
    echo (is_file($realfile))? "<img src='file.jpg'/> FILE" : "<img src='folder.jpg'/> FOLDER ";
    echo "</td><td>" .filesize($realfile)."</td>";
    echo "<td><input type='checkbox' name='delete[]'/></td></tr>";
}
?>

这篇关于filesize():特定路径的统计信息失败-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆