相关文章推荐
买醉的鸡蛋  ·  DevExpress ...·  1 年前    · 
完美的杨桃  ·  Search Results | ...·  1 年前    · 
另类的墨镜  ·  [Swift]Alamofire使用put方 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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:

$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>";

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

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:

$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>"; this is the green check sign on the left? right? i think it is now checked. thx. i am fighting with another 'small' prbm with the same code - trying to give the option to either DOWNLOAD the file (an href url ) or OPEN in case it is a DIRECTORY (folder) with php opendir() or similar. could you give me some ideas. Ivan M Dec 27, 2015 at 16:18

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

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

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

If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Jörg Brüggmann Oct 10, 2021 at 15:50

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .