filesize(): stat failed for specific path - php filesize(): stat failed for specific path - php php php

filesize(): stat failed for specific path - php


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>";}?>


If anyone still encounters this error and the top answer didn't work for you. Then it must be because there is a special character in your filepath i.e. \r or \n

Try:

$f = str_replace(Array("\n", "\r", "\n\r"), '', $f);

This is a common problem for reading content on a file.