[英]Why isn't PHP filesize() function working?
I noticed that filesize doesn't work when I'm trying to list the contents of a directory using a path like this: 我注意到当我尝试使用如下路径列出目录内容时,filesize无法正常工作:
../
for example this works: 例如,这有效:
if ($handle = opendir('./')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "File Name: $file | File Size: ". filesize($file)."<br />";
}
}
closedir($handle);
}
but this doesn't: 但这不是:
if ($handle = opendir('../')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "File Name: $file | File Size: ". filesize($file)."<br />";
}
}
closedir($handle);
}
In the last example the file names are listed fine but instead of getting their file size I get this error: 在上一个示例中,文件名列出的很好,但没有得到它们的文件大小,而是出现此错误:
Warning: filesize() [function.filesize]: stat failed for dynamic.php in C:\xampp\htdocs\app_file_manager\panel\index.php on line 65
Is there a way to get the 2nd example to work? 有没有办法让第二个例子奏效?
filesize($file)
is failing because the $file
is the name of the file that exists in the parent directory and not in the current directory. filesize($file)
失败,因为$file
是父目录中而不是当前目录中存在的文件的名称。
You need to prefix $file
with ../
您需要在
$file
../
加上../
Why don't you define a variable like $basepath
or $downloads
folder path and append the filename to that variable and use filesize()
. 为什么不定义
$basepath
或$downloads
文件夹路径之类的变量,然后将文件名附加到该变量并使用filesize()
。 Be sure to avoid ./
and ../
. 确保避免使用
./
和../
。
$downloads = "www/base/downloads";
$filepath = $downloads."/".$filename;
filesize($filepath)
This should work fine. 这应该工作正常。
Also, problem might be in: 另外,问题可能出在:
[function.filesize]: stat failed
error most offen occurs with file uploaders) [function.filesize]: stat failed
错误,大多数攻击发生在文件上传者身上)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.